1
0
mirror of https://github.com/golang/go synced 2024-09-25 01:20:13 -06:00

Handle \r as a whitespace when parsing JSON string.

Fixes #272.

R=rsc
https://golang.org/cl/161061
This commit is contained in:
Andrew Skiba 2009-11-30 12:03:26 -08:00 committed by Russ Cox
parent c78710f53e
commit 68d3b6e51a
2 changed files with 12 additions and 1 deletions

View File

@ -198,7 +198,7 @@ func punct(c byte) bool {
return c == '"' || c == '[' || c == ']' || c == ':' || c == '{' || c == '}' || c == ','
}
func white(c byte) bool { return c == ' ' || c == '\t' || c == '\n' || c == '\v' }
func white(c byte) bool { return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v' }
func skipwhite(p string, i int) int {
for i < len(p) && white(p[i]) {

View File

@ -66,6 +66,17 @@ func check(t *testing.T, ok bool, name string, v interface{}) {
}
}
const whiteSpaceEncoded = " \t{\n\"s\"\r:\"string\"\v}"
func TestUnmarshalWhitespace(t *testing.T) {
var m myStruct;
ok, errtok := Unmarshal(whiteSpaceEncoded, &m);
if !ok {
t.Fatalf("Unmarshal failed near %s", errtok)
}
check(t, m.S == "string", "string", m.S);
}
func TestUnmarshal(t *testing.T) {
var m myStruct;
m.F = true;