Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json.Parse doesn't treat \r as whitespace #272

Closed
gopherbot opened this issue Nov 19, 2009 · 5 comments
Closed

json.Parse doesn't treat \r as whitespace #272

gopherbot opened this issue Nov 19, 2009 · 5 comments

Comments

@gopherbot
Copy link
Contributor

by metaphorically:

Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
1. Call json.Unmarshal with a valid JSON string containing "\r"
2. errtok in return is set to "\r"

What is the expected output? What do you see instead?
Returned error token is set to "\r". No error should occur.

What is your $GOOS?  $GOARCH?
GOOS=linux
GOARCH=amd64

Which revision are you sync'ed to?  (hg log -l 1)
changeset:   4150:cb559bd8a773
tag:         tip
user:        Robert Griesemer <gri@golang.org>
date:        Thu Nov 19 00:04:30 2009 -0800
summary:     bug219: parsing difficulties with 6g


Please provide any additional information below.

The white() function in json/parse.go is missing | c == '\r'. I've made the
change locally and tested it. I can submit my change to the
codereview.appspot.com.
@griesemer
Copy link
Contributor

Comment 1:

Owner changed to r...@golang.org.

@gopherbot
Copy link
Contributor Author

Comment 2 by skibaa:

working on it

@gopherbot
Copy link
Contributor Author

Comment 3 by skibaa:

done, sending the patch

@gopherbot
Copy link
Contributor Author

Comment 4 by skibaa:

Could not send for review because of a problem with the code review plugin. The patch
includes the change 
Robert suggested and the test. It's really tiny, so I will post it here:
diff -r 44699e529c44 src/pkg/json/parse.go
--- a/src/pkg/json/parse.go Fri Nov 20 15:47:15 2009 -0800
+++ b/src/pkg/json/parse.go Sun Nov 22 00:37:50 2009 +0200
@@ -198,7 +198,7 @@
    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 -r 44699e529c44 src/pkg/json/struct_test.go
--- a/src/pkg/json/struct_test.go   Fri Nov 20 15:47:15 2009 -0800
+++ b/src/pkg/json/struct_test.go   Sun Nov 22 00:37:50 2009 +0200
@@ -64,6 +64,17 @@
    } else {
        t.Logf("%s = %v (good)", name, v)
    }
+}
+
+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) {

@rsc
Copy link
Contributor

rsc commented Nov 30, 2009

Comment 5:

This issue was closed by revision 68d3b6e.

Status changed to Fixed.

Merged into issue #-.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants