From db73fff53b3b3eb6060f1d1c018f80cc0b323499 Mon Sep 17 00:00:00 2001 From: nataliapanferova Date: Fri, 10 Jun 2016 17:45:43 +0200 Subject: [PATCH] fix handling query params * remove the question mark from query param signature * make params optional * fix bug in param parsing --- AWSSignature4DynamicValue.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/AWSSignature4DynamicValue.js b/AWSSignature4DynamicValue.js index 0d2d37a..49757bd 100644 --- a/AWSSignature4DynamicValue.js +++ b/AWSSignature4DynamicValue.js @@ -1,6 +1,6 @@ function getLocation(href) { - var match = href.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)(\/[^?#]*)(\?[^#]*|)(#.*|)$/); + var match = href.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)(\/[^?#]*)(?:\?([^#]*|)(#.*|))?$/); return match && { protocol: match[1], host: match[2], @@ -38,12 +38,16 @@ function getParametersString(request, search) { /* Create the canonicalized query string that you need later in this * procedure: */ + if (search === null || typeof search === "undefined") { + return "" + } + var params = [] /* The parameters can come from the GET URI ... */ var query = search.split('&') - query.forEach(function(params) { - var parts = params.split('=',2) + query.forEach(function(param) { + var parts = param.split('=',2) if (parts.length === 2 && parts[0] !== 'Signature') { params.push(parts) }