Skip to content

Commit

Permalink
Properly decoding + symbols now
Browse files Browse the repository at this point in the history
  • Loading branch information
jheising authored and dougmoscrop committed Jan 15, 2021
1 parent 82743d1 commit f9f47b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
22 changes: 19 additions & 3 deletions lib/provider/aws/clean-up-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,26 @@ function removeBasePath(path = '/', basePath) {
return path;
}

function isString(value)
{
return (typeof value === 'string' || value instanceof String);
}

// ELBs will pass spaces as + symbols, and decodeURIComponent doesn't decode + symbols. So we need to convert them into something it can convert
function specialDecodeURIComponent(value)
{
if(!isString(value))
{
return value;
}

return decodeURIComponent(value.replace(/[+]/g, "%20"));
}

function recursiveURLDecode(value) {

if (typeof value === 'string' || value instanceof String) {
return decodeURIComponent(value);
if (isString(value)) {
return specialDecodeURIComponent(value);
} else if (Array.isArray(value)) {

const decodedArray = [];
Expand All @@ -31,7 +47,7 @@ function recursiveURLDecode(value) {
const decodedObject = {};

for (let key of Object.keys(value)) {
decodedObject[decodeURIComponent(key)] = recursiveURLDecode(value[key]);
decodedObject[specialDecodeURIComponent(key)] = recursiveURLDecode(value[key]);
}

return decodedObject;
Expand Down
8 changes: 4 additions & 4 deletions test/clean-up-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ describe('clean up event', () => {
version: '2.0',
routeKey: '$default',
rawPath: '/my/path',
rawQueryString: 'parameter%231=value%231&parameter%231=value%232&parameter2=value',
rawQueryString: 'parameter%231=value%231&parameter%231=value%232&parameter2=value&parameter3=hello+world',
cookies: ['cookie1', 'cookie2'],
headers: {
'Header1': 'value1',
'Header2': 'value2'
},
queryStringParameters: { 'parameter%231': 'value%231,value%232', 'parameter2': 'value' },
queryStringParameters: { 'parameter%231': 'value%231,value%232', 'parameter2': 'value', 'parameter3': 'hello+world' },
requestContext: {
accountId: '123456789012',
apiId: 'api-id',
Expand Down Expand Up @@ -215,10 +215,10 @@ describe('clean up event', () => {
version: '2.0',
routeKey: '$default',
rawPath: '/path',
rawQueryString: 'parameter%231=value%231&parameter%231=value%232&parameter2=value',
rawQueryString: 'parameter%231=value%231&parameter%231=value%232&parameter2=value&parameter3=hello+world',
cookies: ['cookie1', 'cookie2'],
headers: { Header1: 'value1', Header2: 'value2' },
queryStringParameters: { 'parameter#1': 'value#1,value#2', parameter2: 'value' },
queryStringParameters: { 'parameter#1': 'value#1,value#2', parameter2: 'value', parameter3: 'hello world' },
requestContext: {
accountId: '123456789012',
apiId: 'api-id',
Expand Down

0 comments on commit f9f47b5

Please sign in to comment.