summaryrefslogtreecommitdiff
path: root/src/pkg/json
diff options
context:
space:
mode:
authorAndrew Skiba <skibaa@gmail.com>2009-11-30 12:03:26 -0800
committerAndrew Skiba <skibaa@gmail.com>2009-11-30 12:03:26 -0800
commit00cdce0ef28d7d26fdf862575b74095e394883a8 (patch)
treee51b4651c15c1b30c0ee9f50005c46979897f19e /src/pkg/json
parent8becfe92f8768638faa708a96c5faf7a25ac2f88 (diff)
downloadgolang-00cdce0ef28d7d26fdf862575b74095e394883a8.tar.gz
Handle \r as a whitespace when parsing JSON string.
Fixes issue 272. R=rsc http://codereview.appspot.com/161061 Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/pkg/json')
-rw-r--r--src/pkg/json/parse.go2
-rw-r--r--src/pkg/json/struct_test.go11
2 files changed, 12 insertions, 1 deletions
diff --git a/src/pkg/json/parse.go b/src/pkg/json/parse.go
index 008637593..f9c472977 100644
--- a/src/pkg/json/parse.go
+++ b/src/pkg/json/parse.go
@@ -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]) {
diff --git a/src/pkg/json/struct_test.go b/src/pkg/json/struct_test.go
index caf398b11..c01f4ddeb 100644
--- a/src/pkg/json/struct_test.go
+++ b/src/pkg/json/struct_test.go
@@ -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;