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

Fix json string encoding #122

Merged
merged 2 commits into from
Jun 4, 2018
Merged

Fix json string encoding #122

merged 2 commits into from
Jun 4, 2018

Conversation

vektah
Copy link
Collaborator

@vektah vektah commented May 30, 2018

Fixes #121

Includes a drive by fix for a panic when trying to handle encoding errors.

review appreciated @Teddy-Schmitz

@dannymidnight
Copy link

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"))
Copy link

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?

Copy link
Collaborator Author

@vektah vektah May 31, 2018

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.

Copy link

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

start := 0
io.WriteString(w, `"`)

for i := 0; i < len(s); i++ {
Copy link

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 {

@@ -6,9 +6,41 @@ import (
"strconv"
)

const alphabet = "0123456789ABCDEF"

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.

@Teddy-Schmitz
Copy link

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.

@vektah vektah force-pushed the json-encoding-fixes branch from 2464432 to f207c62 Compare June 4, 2018 08:48
@vektah vektah merged commit a5f7260 into master Jun 4, 2018
@vektah vektah deleted the json-encoding-fixes branch June 4, 2018 08:51
cgxxv pushed a commit to cgxxv/gqlgen that referenced this pull request Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Json unable to marshal response
4 participants