diff --git a/src/routingHeader.ts b/src/routingHeader.ts index 5938c01a5..d30027a73 100644 --- a/src/routingHeader.ts +++ b/src/routingHeader.ts @@ -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. * @@ -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); } diff --git a/test/routingHeader.ts b/test/routingHeader.ts index a5a6d35ff..95e78c0ee 100644 --- a/test/routingHeader.ts +++ b/test/routingHeader.ts @@ -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' + ); + }); });