]> Cypherpunks repositories - gostls13.git/commitdiff
\x00 for NUL in type string.
authorRob Pike <r@golang.org>
Fri, 31 Oct 2008 22:26:14 +0000 (15:26 -0700)
committerRob Pike <r@golang.org>
Fri, 31 Oct 2008 22:26:14 +0000 (15:26 -0700)
R=rsc
DELTA=14  (9 added, 0 deleted, 5 changed)
OCL=18281
CL=18281

src/lib/reflect/test.go
src/lib/reflect/tostring.go
src/lib/reflect/type.go

index 0ed53a3ac4e65bc7ce869bc12a46e8f545b73ccc..9ec22d1ac4478d89652c5257d6513a414ef29cf6 100644 (file)
@@ -119,7 +119,7 @@ func main() {
        typedump("struct {a int8; b int8; c int8; d int8; b int32}", "struct{a int8; b int8; c int8; d int8; b int32}");
        typedump("struct {a int8; b int8; c int8; d int8; e int8; b int32}", "struct{a int8; b int8; c int8; d int8; e int8; b int32}");
        typedump("struct {a int8 \"hi there\"; }", "struct{a int8 \"hi there\"}");
-       typedump("struct {a int8 \"hi \\0there\\t\\n\\\"\\\\\"; }", "struct{a int8 \"hi \\0there\\t\\n\\\"\\\\\"}");
+       typedump("struct {a int8 \"hi \\x00there\\t\\n\\\"\\\\\"; }", "struct{a int8 \"hi \\x00there\\t\\n\\\"\\\\\"}");
 
        valuedump("int8", "8");
        valuedump("int16", "16");
index c57e1995f5759b79b5e3a0e147722ecaa8a5b606..963ab0fbb3e70195122a6952dbd1e838de54e0c1 100644 (file)
@@ -25,7 +25,7 @@ func DoubleQuote(s string) string {
                case '\t':
                        out += `\t`;
                case '\x00':
-                       out += `\0`;
+                       out += `\x00`;
                case '"':
                        out += `\"`;
                case '\\':
index 0d73944bb1ff44587134dbce1edb29603ef1d388..3e5179190cd172cc52f526a97f87ab711e22c0e7 100644 (file)
@@ -453,7 +453,7 @@ func init() {
        typename =
                name '.' name
        doublequotedstring = 
-               string in " ";  escapes are \0 (NUL) \n \t \" \\
+               string in " ";  escapes are \x00 (NUL) \n \t \" \\
        fieldlist =
                [ field { [ ',' | ';' ] field } ]
        field =
@@ -492,6 +492,10 @@ func special(c uint8) bool {
        return false;
 }
 
+func hex00(s string, i int) bool {
+       return i + 2 < len(s) && s[i] == '0' && s[i+1] == '0'
+}
+
 // Process backslashes.  String known to be well-formed.
 // Initial double-quote is left in, as an indication this token is a string.
 func unescape(s string, backslash bool) string {
@@ -509,8 +513,13 @@ func unescape(s string, backslash bool) string {
                                c = '\n';
                        case 't':
                                c = '\t';
-                       case '0':       // it's not a legal go string but \0 means NUL
-                               c = '\x00';
+                       case 'x':
+                               if hex00(s, i+1) {
+                                       i += 2;
+                                       c = 0;
+                                       break;
+                               }
+                       // otherwise just put an 'x'; erroneous but safe.
                        // default is correct already; \\ is \; \" is "
                        }
                }