From 33291c8d08c8edd82e807b8fbe3f1796bcfdb4ac Mon Sep 17 00:00:00 2001 From: tom-marsh Date: Mon, 10 Feb 2020 08:14:33 +0000 Subject: [PATCH] fix: Websocket route names normalization (#7294) --- lib/plugins/aws/lib/naming.js | 10 +++++----- lib/plugins/aws/lib/naming.test.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/plugins/aws/lib/naming.js b/lib/plugins/aws/lib/naming.js index ccef17b32..1e5e59be5 100644 --- a/lib/plugins/aws/lib/naming.js +++ b/lib/plugins/aws/lib/naming.js @@ -208,11 +208,11 @@ module.exports = { getNormalizedWebsocketsRouteKey(route) { return route - .replace('$', 'S') // dollar sign - .replace('/', 'Slash') - .replace('-', 'Dash') - .replace('_', 'Underscore') - .replace('.', 'Period'); + .replace(/\$/g, 'S') // dollar sign + .replace(/\//g, 'Slash') + .replace(/-/g, 'Dash') + .replace(/_/g, 'Underscore') + .replace(/\./g, 'Period'); }, getWebsocketsRouteLogicalId(route) { diff --git a/lib/plugins/aws/lib/naming.test.js b/lib/plugins/aws/lib/naming.test.js index 80026d952..d49b857b4 100644 --- a/lib/plugins/aws/lib/naming.test.js +++ b/lib/plugins/aws/lib/naming.test.js @@ -253,6 +253,18 @@ describe('#naming()', () => { expect(sdk.naming.getNormalizedWebsocketsRouteKey('foo.bar')).to.equal('fooPeriodbar'); }); + + it('converts multiple `-` correctly', () => { + expect(sdk.naming.getNormalizedWebsocketsRouteKey('a-longer-path')).to.equal( + 'aDashlongerDashpath' + ); + }); + + it('converts multiple `-` and `_` correctly', () => { + expect(sdk.naming.getNormalizedWebsocketsRouteKey('a-long_er-path_still')).to.equal( + 'aDashlongUnderscoreerDashpathUnderscorestill' + ); + }); }); describe('#getWebsocketsRouteLogicalId()', () => {