Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix to the old fix.

  • Loading branch information...
commit 5f2b9aeb05b5b4c10cd4d29374f7ed1dbaca8ae4 1 parent c637066
@assaf authored
View
2  CHANGELOG.md
@@ -11,7 +11,7 @@ Fixes #71 cookie names now preserve case.
Fixes #69 incorrectly resolving partial URLs in XHR requests.
- 294 Tests
+ 299 Tests
3.7 sec to complete
View
19 spec/xhr-spec.coffee
@@ -45,6 +45,19 @@ brains.get "/xhr/parturl", (req, res)-> res.send """
</html>
"""
+brains.get "/xhr/postempty", (req, res)-> res.send """
+ <html>
+ <head><script src="/jquery.js"></script></head>
+ <body>
+ <script>
+ $.post("/xhr/postempty", function(response) { window.response = "ok" });
+ </script>
+ </body>
+ </html>
+ """
+brains.post "/xhr/postempty", (req, res)-> res.send ""
+
+
vows.describe("XMLHttpRequest").addBatch(
"load asynchronously":
zombie.wants "http://localhost:3003/xhr"
@@ -63,6 +76,12 @@ vows.describe("XMLHttpRequest").addBatch(
"should send cookies in XHR response": (browser)-> assert.equal browser.window.response, "redirected: yes"
"handle partial URLs":
+ # If the request URL is http://:3003 it means use the current document's hostname, but the port 3003.
zombie.wants "http://localhost:3003/xhr/parturl"
"should resolve partial URL": (browser)-> assert.equal browser.window.response, "ok"
+
+ "handle POST requests with no data":
+ zombie.wants "http://localhost:3003/xhr/postempty"
+ "should post with no data": (browser)-> assert.equal browser.window.response, "ok"
+
).export(module)
View
2  src/zombie/resources.coffee
@@ -267,7 +267,7 @@ class Resources extends Array
else ''
stringify = (object) =>
- return object if typeOf(object) == '[object String]'
+ return object.toString() unless object.map
object.map((k) ->
if Array.isArray(k[1])
k[1].map((v) ->
View
4 src/zombie/xhr.coffee
@@ -36,7 +36,9 @@ XMLHttpRequest = (window)->
method = method.toUpperCase()
throw new core.DOMException(core.SECURITY_ERR, "Unsupported HTTP method") if /^(CONNECT|TRACE|TRACK)$/.test(method)
throw new core.DOMException(core.SYNTAX_ERR, "Unsupported HTTP method") unless /^(DELETE|GET|HEAD|OPTIONS|POST|PUT)$/.test(method)
- url = URL.parse(URL.resolve(url, window.location.href))
+ url = URL.parse(URL.resolve(window.location.href, url))
+ url.hostname ||= window.location.hostname
+ url.host = "#{url.hostname}:#{url.port}"
url.hash = null
throw new core.DOMException(core.SECURITY_ERR, "Cannot make request to different domain") unless url.host == window.location.host
throw new core.DOMException(core.NOT_SUPPORTED_ERR, "Only HTTP protocol supported") unless url.protocol == "http:"
Please sign in to comment.
Something went wrong with that request. Please try again.