Skip to content

Bring string handling more in line with real Go #6

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

Merged
merged 3 commits into from
Jan 28, 2015
Merged

Bring string handling more in line with real Go #6

merged 3 commits into from
Jan 28, 2015

Conversation

dominikh
Copy link
Owner

No description provided.

@dmitshur
Copy link
Contributor

LGTM.

The overall change is good and closes #3 (you should mention that). Docs seem clear and accurate to me. I've also tested it in my code, and it compiled and ran correctly.

// req := xhr.NewRequest("POST", "http://example.com")
// req.ResponseType = xhr.ArrayBuffer
// req.Send([]byte("data"))
// b := js.Global.Get("Uint8Array").New(req.Response).Interface().([]byte)
Copy link
Contributor

Choose a reason for hiding this comment

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

While this is a logical place for this information to be, I do think it would be more visible and helpful overall to simply move this section to the end of package overview docs.

In Go, strings are usually considered immutable byte slices, and their
encoding doesn't matter, at least not when transmitting them as data.

JavaScript has a different idea, which leads to strings being sanitized
so that they contain valid UTF-8, by replacing invalid byte sequences
with replacement runes.

Since we're writing this package primarily for Go programmers, we want
it to behave as close to "real" Go as possible. That's why the top level
Send function is changed to receive binary data and return []byte, and
why Request.Send is changed to never pass strings to JS, only []byte.

This makes it impossible for someone to actually make use of
aforementioned sanitization for outgoing strings, but there's no reason
XHR itself should be doing it, and it can be solved in pure Go with a
loop.

See the discussion at #3 for
more information.
Do not convert string to []byte, and explain how to recreate the
behaviour of xhr.Send.
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.

2 participants