Permalink
Browse files

Fixes #69 incorrectly resolving partial URLs in XHR requests.

  • Loading branch information...
1 parent a74419f commit c6370668f80b0bcbb56aa83d452087ef823bc426 @assaf assaf committed Feb 2, 2011
Showing with 23 additions and 7 deletions.
  1. +3 −1 CHANGELOG.md
  2. +19 −5 spec/xhr-spec.coffee
  3. +1 −1 src/zombie/xhr.coffee
View
@@ -9,7 +9,9 @@ Upgraded to HTML5 0.2.13.
Fixes #71 cookie names now preserve case.
- 292 Tests
+Fixes #69 incorrectly resolving partial URLs in XHR requests.
+
+ 294 Tests
3.7 sec to complete
View
@@ -8,12 +8,12 @@ brains.get "/xhr", (req, res)->
<head><script src="/jquery.js"></script></head>
<body>
<script>
- $.get("/backend", function(response) { window.response = response });
+ $.get("/xhr/backend", function(response) { window.response = response });
</script>
</body>
</html>
"""
-brains.get "/backend", (req, res)->
+brains.get "/xhr/backend", (req, res)->
res.cookie "xml", "lol", "Path": "/"
response = req.cookies["xhr"] || ""
response = "redirected: #{response}" if req.query.redirected
@@ -26,14 +26,24 @@ brains.get "/xhr/redirect", (req, res)->
<head><script src="/jquery.js"></script></head>
<body>
<script>
- $.get("/backend/redirect", function(response) { window.response = response });
+ $.get("/xhr/redirect/backend", function(response) { window.response = response });
</script>
</body>
</html>
"""
-brains.get "/backend/redirect", (req, res)->
- res.redirect "/backend?redirected=true"
+brains.get "/xhr/redirect/backend", (req, res)->
+ res.redirect "/xhr/backend?redirected=true"
+brains.get "/xhr/parturl", (req, res)-> res.send """
+ <html>
+ <head><script src="/jquery.js"></script></head>
+ <body>
+ <script>
+ $.get("http://:3003", function(response) { window.response = "ok" });
+ </script>
+ </body>
+ </html>
+ """
vows.describe("XMLHttpRequest").addBatch(
"load asynchronously":
@@ -51,4 +61,8 @@ vows.describe("XMLHttpRequest").addBatch(
"redirect":
zombie.wants "http://localhost:3003/xhr/redirect"
"should send cookies in XHR response": (browser)-> assert.equal browser.window.response, "redirected: yes"
+
+ "handle partial URLs":
+ zombie.wants "http://localhost:3003/xhr/parturl"
+ "should resolve partial URL": (browser)-> assert.equal browser.window.response, "ok"
).export(module)
@@ -36,7 +36,7 @@ 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(window.location, url))
+ url = URL.parse(URL.resolve(url, window.location.href))
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:"

0 comments on commit c637066

Please sign in to comment.