@@ -10,14 +10,15 @@ import (
10
10
var testCasesUnquote = []struct {
11
11
quoted string
12
12
unquoted string
13
- // If this is non-empty it means that quoteing back unqoted string does not
14
- // produce same result bit-wise.
15
- // This happens when we lose the information about original escape sequence (octal, hex)
16
- // Golang unquote() defaults to hex format, so it's used as canonical one.
13
+ // In some cases unquoting and then re-quoting a quoted string does not produce a
14
+ // string that is bitwise identical to the original, even though they denote the same bytes.
15
+ // This can happen, e.g, if we switch between hex and octal encoding of a byte.
16
+ // Test cases where this happens set canonicalUnquoted to the string that is expected
17
+ // to be decoded via Go's native rules to the byte sequence we want.
17
18
canonicalQuoted string
18
19
}{
19
- {`'a'` , "a" , "" },
20
- {`'\x00'` , "\u0000 " , "" },
20
+ {`'a'` , "a" , `'a'` },
21
+ {`'\x00'` , "\u0000 " , `'\x00'` },
21
22
{`'\0'` , "\u0000 " , "'\\ x00'" },
22
23
{`'\0something\0'` , "\u0000 something\u0000 " , "'\\ x00something\\ x00'" },
23
24
{`'\0something\0else'` , "\u0000 something\u0000 else" , "'\\ x00something\\ x00else'" },
@@ -41,11 +42,7 @@ func TestUnquoteSingleAndQuoteBack(t *testing.T) {
41
42
require .NoError (t , err )
42
43
43
44
q := quoteSingle (u )
44
- if test .canonicalQuoted != "" {
45
- assertEquals (t , test .canonicalQuoted , q )
46
- } else {
47
- assertEquals (t , test .quoted , q )
48
- }
45
+ assertEquals (t , test .canonicalQuoted , q )
49
46
})
50
47
}
51
48
}
0 commit comments