Make sure XMLHttpRequest#responseText is always a string #466

merged 2 commits into from Jan 9, 2013


None yet

2 participants


The XMLHttpRequest Level 2 specification requires the responseText attribute to be a "text response entity body". Accoding to the relevant section in the spec, this means that it must always be a string, regardless of the response's content type.

The commit of this pull request adjusts zombie.js to match this behavior. Previously, responseText would be a Buffer in such cases.

@assaf assaf and 1 other commented on an outdated diff Jan 7, 2013
@@ -132,7 +132,7 @@ class XMLHttpRequest
@_responseHeaders = response.headers
@_stateChanged(XMLHttpRequest.HEADERS_RECEIVED, listener)
- @responseText = response.body
+ @responseText = @_textBody(response.body)
assaf Jan 7, 2013

Why not just response.body.toString()?

denisw Jan 7, 2013

I originally did it this way because response.body might be undefined, in which case a direct toString() call would fail (this happens in the "response headers" test). But looking at the spec again, this case needs to be handled slightly differently because responseText should be the empty string in this case. I'll push a revised version.


Is the patch OK in it's current form?

@assaf assaf merged commit 8e1fa4a into assaf:master Jan 9, 2013

1 check passed

Details default The Travis build passed

For the record, when you update a PR, Github doesn't send out any notification, so always follow with a comment indicating you made a change.


Thanks for pointing this out, I forget it all the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment