Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / handlers / uri-context / normalise-redirect.js
blob32bef62ac21811814eda3b7c3cfde82a80666bda
1 'use strict';
3 var url = require('url');
5 function normalizeRedirect(roomUrl, req) {
6 var pathname = url.parse(roomUrl).pathname;
8 // Do we need to add the subframe on too?
9 var m = req.path.match(/\/~\w+$/);
10 var frame = (m && m[0]) || '';
11 if (frame) {
12 pathname = pathname + frame;
14 pathname = encodeURI(pathname);
16 return url.format({ pathname: pathname, query: req.query });
19 module.exports = normalizeRedirect;