From 7732d2b88de8a892755045da0bff8839df907aed Mon Sep 17 00:00:00 2001 From: tiziano Date: Fri, 29 Jul 2016 12:21:07 +0200 Subject: [PATCH 1/5] Fixed issues with filename with strange chars in --- client/js/s3/request-signer.js | 3 ++- client/js/s3/s3.xhr.upload.handler.js | 6 ++++-- client/js/s3/util.js | 23 ++++++++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/client/js/s3/request-signer.js b/client/js/s3/request-signer.js index 4fdf6c32b..2ca6dbb76 100644 --- a/client/js/s3/request-signer.js +++ b/client/js/s3/request-signer.js @@ -148,7 +148,8 @@ qq.s3.RequestSigner = function(o) { if (queryParamIdx > 0) { path = endOfUri.substr(0, queryParamIdx); } - return escape("/" + decodeURIComponent(path)); + return "/"+path; + //return escape("/" + decodeURIComponent(path)); }, getEncodedHashedPayload: function(body) { diff --git a/client/js/s3/s3.xhr.upload.handler.js b/client/js/s3/s3.xhr.upload.handler.js index 481cc7e82..579d0cbf1 100755 --- a/client/js/s3/s3.xhr.upload.handler.js +++ b/client/js/s3/s3.xhr.upload.handler.js @@ -456,8 +456,10 @@ qq.s3.XhrUploadHandler = function(spec, proxy) { }, urlSafe: function(id) { - var encodedKey = encodeURIComponent(handler.getThirdPartyFileId(id)); - return encodedKey.replace(/%2F/g, "/"); + var encodedKey = handler.getThirdPartyFileId(id); + return qq.s3.uriEscapePath(encodedKey); + // var encodedKey = encodeURIComponent(handler.getThirdPartyFileId(id)); + // return encodedKey.replace(/%2F/g, "/"); } }, diff --git a/client/js/s3/util.js b/client/js/s3/util.js index ba4423fd4..58a968090 100644 --- a/client/js/s3/util.js +++ b/client/js/s3/util.js @@ -491,6 +491,27 @@ qq.s3.util = qq.s3.util || (function() { // replace percent-encoded spaces with a "+" return percentEncoded.replace(/%20/g, "+"); - } + }, + /** + * Escapes url part as for AWS requirements + */ + uriEscape: function(string) { + var output = encodeURIComponent(string); + output = output.replace(/[^A-Za-z0-9_.~\-%]+/g, escape); + output = output.replace(/[*]/g, function(ch) { + return '%' + ch.charCodeAt(0).toString(16).toUpperCase(); + }); + return output; + }, + /** + * Escapes a path as for AWS requirement + */ + uriEscapePath: function(path){ + var parts = []; + qq.each(path.split('/'),function(idx,item){ + parts.push(qq.s3.util.uriEscape(item)) + }); + return parts.join('/'); + }, }; }()); From f26f0c98a63e4f7fd00986650c50fc2100540e64 Mon Sep 17 00:00:00 2001 From: e-tip Date: Fri, 29 Jul 2016 13:24:41 +0200 Subject: [PATCH 2/5] Fixed issues in s3 uploader where signature isn't correctly computed --- client/js/s3/request-signer.js | 2 +- client/js/s3/s3.xhr.upload.handler.js | 2 +- client/js/s3/util.js | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client/js/s3/request-signer.js b/client/js/s3/request-signer.js index 2ca6dbb76..21a8797cb 100644 --- a/client/js/s3/request-signer.js +++ b/client/js/s3/request-signer.js @@ -148,7 +148,7 @@ qq.s3.RequestSigner = function(o) { if (queryParamIdx > 0) { path = endOfUri.substr(0, queryParamIdx); } - return "/"+path; + return "/" + path; //return escape("/" + decodeURIComponent(path)); }, diff --git a/client/js/s3/s3.xhr.upload.handler.js b/client/js/s3/s3.xhr.upload.handler.js index 579d0cbf1..e8ae75174 100755 --- a/client/js/s3/s3.xhr.upload.handler.js +++ b/client/js/s3/s3.xhr.upload.handler.js @@ -457,7 +457,7 @@ qq.s3.XhrUploadHandler = function(spec, proxy) { urlSafe: function(id) { var encodedKey = handler.getThirdPartyFileId(id); - return qq.s3.uriEscapePath(encodedKey); + return qq.s3.util.uriEscapePath(encodedKey); // var encodedKey = encodeURIComponent(handler.getThirdPartyFileId(id)); // return encodedKey.replace(/%2F/g, "/"); } diff --git a/client/js/s3/util.js b/client/js/s3/util.js index 58a968090..b5253fcef 100644 --- a/client/js/s3/util.js +++ b/client/js/s3/util.js @@ -495,23 +495,23 @@ qq.s3.util = qq.s3.util || (function() { /** * Escapes url part as for AWS requirements */ - uriEscape: function(string) { + uriEscape: function(string) { var output = encodeURIComponent(string); output = output.replace(/[^A-Za-z0-9_.~\-%]+/g, escape); output = output.replace(/[*]/g, function(ch) { - return '%' + ch.charCodeAt(0).toString(16).toUpperCase(); + return "%" + ch.charCodeAt(0).toString(16).toUpperCase(); }); return output; - }, + }, /** * Escapes a path as for AWS requirement */ - uriEscapePath: function(path){ + uriEscapePath: function(path) { var parts = []; - qq.each(path.split('/'),function(idx,item){ - parts.push(qq.s3.util.uriEscape(item)) + qq.each(path.split("/"), function(idx, item) { + parts.push(qq.s3.util.uriEscape(item)); }); - return parts.join('/'); - }, + return parts.join("/"); + } }; }()); From 93bf45a59f37ae2f78da5845517ef47ec2bc73a6 Mon Sep 17 00:00:00 2001 From: e-tip Date: Fri, 29 Jul 2016 17:06:38 +0200 Subject: [PATCH 3/5] Removed commented code --- client/js/s3/request-signer.js | 1 - client/js/s3/s3.xhr.upload.handler.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/client/js/s3/request-signer.js b/client/js/s3/request-signer.js index 21a8797cb..dcc8ce422 100644 --- a/client/js/s3/request-signer.js +++ b/client/js/s3/request-signer.js @@ -149,7 +149,6 @@ qq.s3.RequestSigner = function(o) { path = endOfUri.substr(0, queryParamIdx); } return "/" + path; - //return escape("/" + decodeURIComponent(path)); }, getEncodedHashedPayload: function(body) { diff --git a/client/js/s3/s3.xhr.upload.handler.js b/client/js/s3/s3.xhr.upload.handler.js index e8ae75174..46572e7b0 100755 --- a/client/js/s3/s3.xhr.upload.handler.js +++ b/client/js/s3/s3.xhr.upload.handler.js @@ -458,8 +458,6 @@ qq.s3.XhrUploadHandler = function(spec, proxy) { urlSafe: function(id) { var encodedKey = handler.getThirdPartyFileId(id); return qq.s3.util.uriEscapePath(encodedKey); - // var encodedKey = encodeURIComponent(handler.getThirdPartyFileId(id)); - // return encodedKey.replace(/%2F/g, "/"); } }, From 2048f7dafb9e3b216d418c1ad460814aa5441bf7 Mon Sep 17 00:00:00 2001 From: e-tip Date: Tue, 20 Sep 2016 09:45:10 +0200 Subject: [PATCH 4/5] Wrote tests for function uriEscapePath --- test/unit/s3/util.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/unit/s3/util.js b/test/unit/s3/util.js index 08071d449..72422cdc7 100644 --- a/test/unit/s3/util.js +++ b/test/unit/s3/util.js @@ -153,6 +153,16 @@ describe("s3/util.js", function () { assert.equal(response.etag, "789"); }); }); + + describe("uriEscapePath",function(){ + it("encodes params following s3 directives",function(){ + assert.equal(qq.s3.util.uriEscapePath("pippo/pluto e topolino.jpg"),"pippo/pluto%20e%20topolino.jpg"); + assert.equal(qq.s3.util.uriEscapePath("pippo/pluto & mickey+mouse.jpg"),"pippo/pluto%20%26%20mickey%2Bmouse.jpg"); + assert.equal(qq.s3.util.uriEscapePath("pluto & àòè.jpg"),"pluto%20%26%20a%CC%80o%CC%80e%CC%80.jpg"); + assert.equal(qq.s3.util.uriEscapePath("pluto & micke#22.jpg"),"pluto%20%26%20micke%2322.jpg"); + assert.equal(qq.s3.util.uriEscapePath("pluto_lkjhàò=23£"),"pluto_lkjha%CC%80o%CC%80%3D23%C2%A3"); + }); + }); describe("encodeQueryStringParam", function() { it("handles params with spaces correctly", function() { From 0e5b91192bfc958003805de16fc24000a45152c8 Mon Sep 17 00:00:00 2001 From: e-tip Date: Thu, 22 Sep 2016 10:05:03 +0200 Subject: [PATCH 5/5] Added comment that attributes uriEscape function code to AWS released under Apache 2.0 license --- client/js/s3/util.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/js/s3/util.js b/client/js/s3/util.js index b5253fcef..544feb7ed 100644 --- a/client/js/s3/util.js +++ b/client/js/s3/util.js @@ -494,6 +494,7 @@ qq.s3.util = qq.s3.util || (function() { }, /** * Escapes url part as for AWS requirements + * AWS uriEscapePath function pulled from aws-sdk-js licensed under Apache 2.0 - http://github.com/aws/aws-sdk-js */ uriEscape: function(string) { var output = encodeURIComponent(string); @@ -505,6 +506,7 @@ qq.s3.util = qq.s3.util || (function() { }, /** * Escapes a path as for AWS requirement + * AWS uriEscapePath function pulled from aws-sdk-js licensed under Apache 2.0 - http://github.com/aws/aws-sdk-js */ uriEscapePath: function(path) { var parts = [];