mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-13 22:47:30 +00:00
net/dns: detect and decode UTF-16 from wsl.exe earlier.
Fixes #3170 Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:

committed by
Dave Anderson

parent
e16cb523aa
commit
124363e0ca
25
net/dns/utf_test.go
Normal file
25
net/dns/utf_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package dns
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMaybeUnUTF16(t *testing.T) {
|
||||
tests := []struct {
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{"abc", "abc"}, // UTF-8
|
||||
{"a\x00b\x00c\x00", "abc"}, // UTF-16-LE
|
||||
{"\x00a\x00b\x00c", "abc"}, // UTF-16-BE
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
got := string(maybeUnUTF16([]byte(test.in)))
|
||||
if got != test.want {
|
||||
t.Errorf("maybeUnUTF16(%q) = %q, want %q", test.in, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user