Skip to content

Commit

Permalink
fix: routing header parameters must be urlencoded (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster authored and JustinBeckwith committed Jun 20, 2019
1 parent e398b8b commit 4ade536
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/routingHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import * as querystring from 'querystring';

/**
* Helpers for constructing routing headers.
*
Expand All @@ -44,8 +46,9 @@
* @param {Object} params - the request header parameters.
* @return {string} the routing header value.
*/
export function fromParams(params: {[index: string]: {}}): string {
return Object.keys(params)
.map(key => `${key}=${params[key]}`)
.join('&');

export function fromParams(params: {
[index: string]: string | number | boolean;
}): string {
return querystring.stringify(params);
}
7 changes: 7 additions & 0 deletions test/routingHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ describe('fromParams', () => {
const routingHeader = fromParams({name: 'foo', 'book.read': true});
expect(routingHeader).to.equal('name=foo&book.read=true');
});

it('encodes non-ASCII characters', () => {
const routingHeader = fromParams({screaming: '😱', cyrillic: 'тест'});
expect(routingHeader).to.equal(
'screaming=%F0%9F%98%B1&cyrillic=%D1%82%D0%B5%D1%81%D1%82'
);
});
});

0 comments on commit 4ade536

Please sign in to comment.