Skip to content

Commit 354e69e

Browse files
author
John Soo
committed
Add test for relative url resolution on redirect.
1 parent cd55b2d commit 354e69e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

test/src/helpers/xhr_server.coffee

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ class XhrServer
119119
# Returns a HTTP redirect. Used to test the redirection handling code.
120120
@app.all '/_/redirect/:status/:next_page', (request, response) =>
121121
response.statusCode = parseInt(request.params.status)
122-
response.header 'Location',
123-
"http://#{request.get('host')}/_/#{request.params.next_page}"
122+
if request.query.relative
123+
url = "/#{request.params.next_page}"
124+
else
125+
url = "http://#{request.get('host')}/_/#{request.params.next_page}"
126+
response.header 'Location', url
124127
body = "<p>This is supposed to have a redirect link</p>"
125128
response.header 'Content-Type', 'text/html'
126129
response.header 'Content-Length', body.length.toString()

test/src/redirect_test.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ describe 'XMLHttpRequest', ->
1919
done()
2020
@xhr.send()
2121

22+
it 'resolves effective request uri for the next location', (done) ->
23+
@xhr.open 'GET', 'http://localhost:8912/_/redirect/302/method?relative=true'
24+
@xhr.onload = =>
25+
expect(@xhr._url['href']).to.match(/http:\/\/localhost:8912\/method/)
26+
done()
27+
@xhr.send()
28+
2229
it 'persists custom request headers across redirects', (done) ->
2330
@xhr.open 'GET', 'http://localhost:8912/_/redirect/302/headers'
2431
@xhr.setRequestHeader 'X-Redirect-Test', 'should be preserved'

0 commit comments

Comments
 (0)