Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #466 from denisw/master

Make sure XMLHttpRequest#responseText is always a string
  • Loading branch information...
commit 8e1fa4a4440fa9449a67c056060dd3f3ae855fb2 2 parents 9edfadb + f4fca71
@assaf authored
Showing with 54 additions and 1 deletion.
  1. +2 −1  lib/zombie/xhr.coffee
  2. +52 −0 test/xhr_test.coffee
View
3  lib/zombie/xhr.coffee
@@ -132,7 +132,7 @@ class XMLHttpRequest
@_responseHeaders = response.headers
@_stateChanged(XMLHttpRequest.HEADERS_RECEIVED, listener)
- @responseText = response.body
+ @responseText = response.body?.toString() || ""
@responseXML = null
@_stateChanged(XMLHttpRequest.DONE, listener)
@@ -157,6 +157,7 @@ class XMLHttpRequest
listener.call(this)
catch error
raise(element: @_window.document, from: __filename, scope: "XHR", error: error)
+
# Lifecycle states
View
52 test/xhr_test.coffee
@@ -154,6 +154,58 @@ describe "XMLHttpRequest", ->
it "should post with no data", ->
browser.assert.text "title", "201posted"
+ describe "empty response", ->
+ before (done)->
+ brains.get "/xhr/get-empty", (req, res)->
+ res.send """
+ <html>
+ <head><script src="/jquery.js"></script></head>
+ <body>
+ <script>
+ $.get("/xhr/empty", function(response, status, xhr) {
+ document.text = xhr.responseText;
+ });
+ </script>
+ </body>
+ </html>
+ """
+ brains.get "/xhr/empty", (req, res)->
+ res.send ""
+ brains.ready done
+
+ before (done)->
+ browser.visit("http://localhost:3003/xhr/get-empty", done)
+
+ it "responseText should be an empty string", ->
+ assert.strictEqual "", browser.document.text
+
+ describe "response text", ->
+ before (done)->
+ brains.get "/xhr/get-utf8-octet-stream", (req, res)->
+ res.send """
+ <html>
+ <head><script src="/jquery.js"></script></head>
+ <body>
+ <script>
+ $.get("/xhr/utf8-octet-stream", function(response, status, xhr) {
+ document.text = xhr.responseText;
+ });
+ </script>
+ </body>
+ </html>
+ """
+ brains.get "/xhr/utf8-octet-stream", (req, res)->
+ res.type "application/octet-stream"
+ res.send "Text"
+ brains.ready done
+
+ before (done)->
+ browser.visit("http://localhost:3003/xhr/get-utf8-octet-stream", done)
+
+ it "responseText should be a string", ->
+ assert.equal "string", typeof browser.document.text
+ assert.equal "Text", browser.document.text
+
describe "HTML document", ->
before (done)->
Please sign in to comment.
Something went wrong with that request. Please try again.