-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix json string encoding #122
Conversation
Nice one 👍 |
assert.Equal(t, `"quotes\"nested\"in\"quotes\""`, doStrMarshal(`quotes"nested"in"quotes"`)) | ||
assert.Equal(t, `"\u0000"`, doStrMarshal("\u0000")) | ||
assert.Equal(t, `"\u0000"`, doStrMarshal("\u0000")) | ||
assert.Equal(t, "\"\U000fe4ed\"", doStrMarshal("\U000fe4ed")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit/curios: why double quotes around expected val here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because raw strings can't have escaped literals, and I didn't want the raw unicode fe4ed in the source document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just pointing out that you are using double quotes around expected string in the last test case vs. back ticks for all other test cases. It seems semantically it is all the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
graphql/string.go
Outdated
start := 0 | ||
io.WriteString(w, `"`) | ||
|
||
for i := 0; i < len(s); i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: replace with for i, c := range s {
graphql/string.go
Outdated
@@ -6,9 +6,41 @@ import ( | |||
"strconv" | |||
) | |||
|
|||
const alphabet = "0123456789ABCDEF" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a small thing but maybe call this unicodeAlphabet
or something similar as I could see someone looking at the var name and wondering why it doesn't encompass the whole alphabet.
I can confirm that my test repo no longer panics with this fix applied and it returns the string as intended. I looked through everything else and it seems ok. I'm not really an expert on string handling though so I can't say I feel qualified to review that part. |
2464432
to
f207c62
Compare
Fix json string encoding
Fixes #121
Includes a drive by fix for a panic when trying to handle encoding errors.
review appreciated @Teddy-Schmitz