summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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;