Merge pull request #932 from sharelatex/as-redirect-query-string

Support passing through query params in redirects
This commit is contained in:
Timothée Alby 2018-09-18 12:35:21 +01:00 committed by GitHub
commit b16cffe587
3 changed files with 13 additions and 2 deletions

View file

@ -23,4 +23,11 @@ module.exports = RedirectManager =
url = target.url url = target.url
if target.baseUrl? if target.baseUrl?
url = "#{target.baseUrl}#{url}" url = "#{target.baseUrl}#{url}"
res.redirect code, url res.redirect code, url + getQueryString(req)
# Naively get the query params string. Stringifying the req.query object may
# have differences between Express and Rails, so safer to just pass the raw
# string
getQueryString = (req) ->
qs = req.url.match(/\?.*$/)
if qs? then qs[0] else ""

View file

@ -29,3 +29,6 @@ describe "RedirectUrls", ->
it 'proxy URLs with multiple support methods', (done) -> it 'proxy URLs with multiple support methods', (done) ->
assertRedirect 'get', '/redirect/get_and_post', 302, '/destination/get_and_post', done assertRedirect 'get', '/redirect/get_and_post', 302, '/destination/get_and_post', done
it 'redirects with query params', (done) ->
assertRedirect 'get', '/redirect/qs?foo=bar&baz[]=qux1&baz[]=qux2', 302, '/destination/qs?foo=bar&baz[]=qux1&baz[]=qux2', done

View file

@ -125,4 +125,5 @@ module.exports =
}, },
'/redirect/params/:id': { '/redirect/params/:id': {
url: (params) -> "/destination/#{params.id}/params" url: (params) -> "/destination/#{params.id}/params"
} },
'/redirect/qs': '/destination/qs'