@@ -10,14 +10,15 @@ import (
1010var testCasesUnquote = []struct {
1111 quoted string
1212 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.
1718 canonicalQuoted string
1819}{
19- {`'a'` , "a" , "" },
20- {`'\x00'` , "\u0000 " , "" },
20+ {`'a'` , "a" , `'a'` },
21+ {`'\x00'` , "\u0000 " , `'\x00'` },
2122 {`'\0'` , "\u0000 " , "'\\ x00'" },
2223 {`'\0something\0'` , "\u0000 something\u0000 " , "'\\ x00something\\ x00'" },
2324 {`'\0something\0else'` , "\u0000 something\u0000 else" , "'\\ x00something\\ x00else'" },
@@ -41,11 +42,7 @@ func TestUnquoteSingleAndQuoteBack(t *testing.T) {
4142 require .NoError (t , err )
4243
4344 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 )
4946 })
5047 }
5148}
0 commit comments