diff --git a/app/lib/methods/helpers/parseQuery.test.ts b/app/lib/methods/helpers/parseQuery.test.ts new file mode 100644 index 00000000000..128199cca1a --- /dev/null +++ b/app/lib/methods/helpers/parseQuery.test.ts @@ -0,0 +1,18 @@ +import parseQuery from './parseQuery'; + +describe('parseQuery', () => { + it('preserves query values that contain equals signs', () => { + expect(parseQuery('host=open.rocket.chat&token=abc==&type=auth')).toEqual({ + host: 'open.rocket.chat', + token: 'abc==', + type: 'auth' + }); + }); + + it('decodes plus signs and encoded equals signs in values', () => { + expect(parseQuery('fullURL=https%3A%2F%2Fgo.rocket.chat%2Fauth%3Ftoken%3Da%252Bb%253D%253D&message=hello+world')).toEqual({ + fullURL: 'https://go.rocket.chat/auth?token=a%2Bb%3D%3D', + message: 'hello world' + }); + }); +}); diff --git a/app/lib/methods/helpers/parseQuery.ts b/app/lib/methods/helpers/parseQuery.ts index 8e3d7abe8c6..1a24aea660d 100644 --- a/app/lib/methods/helpers/parseQuery.ts +++ b/app/lib/methods/helpers/parseQuery.ts @@ -15,7 +15,9 @@ export default function (query: string) { } return (/^[?#]/.test(query) ? query.slice(1) : query).split('&').reduce((params: { [key: string]: string }, param) => { - const [key, value] = param.split('='); + const separatorIndex = param.indexOf('='); + const key = separatorIndex >= 0 ? param.slice(0, separatorIndex) : param; + const value = separatorIndex >= 0 ? param.slice(separatorIndex + 1) : ''; params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : ''; return params; }, {});