mirror of
https://github.com/golang/go
synced 2024-11-12 07:50:23 -07:00
Handle \r as a whitespace when parsing JSON string.
Fixes #272. R=rsc https://golang.org/cl/161061
This commit is contained in:
parent
c78710f53e
commit
68d3b6e51a
@ -198,7 +198,7 @@ func punct(c byte) bool {
|
|||||||
return c == '"' || c == '[' || c == ']' || c == ':' || c == '{' || c == '}' || c == ','
|
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 {
|
func skipwhite(p string, i int) int {
|
||||||
for i < len(p) && white(p[i]) {
|
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) {
|
func TestUnmarshal(t *testing.T) {
|
||||||
var m myStruct;
|
var m myStruct;
|
||||||
m.F = true;
|
m.F = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user