Commit 68d3b6e5 authored by Andrew Skiba's avatar Andrew Skiba Committed by Russ Cox

Handle \r as a whitespace when parsing JSON string.

Fixes #272.

R=rsc
https://golang.org/cl/161061
parent c78710f5
......@@ -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]) {
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment