Skip to content

Commit

Permalink
fix: unescape plus in ALB query string (#660)
Browse files Browse the repository at this point in the history
Co-authored-by: Johan Levin <johan.levin@picadeli.se>
  • Loading branch information
johan13 and Johan Levin committed Oct 24, 2023
1 parent 75e9de3 commit ebd42d4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/event-sources/aws/alb.js
Expand Up @@ -13,13 +13,13 @@ function getPathWithQueryStringUseUnescapeParams ({
// decode everything back into utf-8 text.
if (event.multiValueQueryStringParameters) {
for (const key in event.multiValueQueryStringParameters) {
const formattedKey = decodeURIComponent(key)
query[formattedKey] = event.multiValueQueryStringParameters[key].map(value => decodeURIComponent(value))
const formattedKey = decodeUrlencoded(key)
query[formattedKey] = event.multiValueQueryStringParameters[key].map(value => decodeUrlencoded(value))
}
} else {
for (const key in event.queryStringParameters) {
const formattedKey = decodeURIComponent(key)
query[formattedKey] = decodeURIComponent(event.queryStringParameters[key])
const formattedKey = decodeUrlencoded(key)
query[formattedKey] = decodeUrlencoded(event.queryStringParameters[key])
}
}

Expand All @@ -29,6 +29,11 @@ function getPathWithQueryStringUseUnescapeParams ({
})
}

// Decode an "application/x-www-form-urlencoded" encoded string.
function decodeUrlencoded (val) {
return decodeURIComponent(val.replace(/\+/g, '%20'))
}

const getRequestValuesFromAlbEvent = ({ event }) => {
const values = getRequestValuesFromEvent({
event,
Expand Down

0 comments on commit ebd42d4

Please sign in to comment.