Permalink
Browse files

when encoding the filename, using encodeURLComponent instead of encod…

…eURL
  • Loading branch information...
1 parent c7048cc commit 5af56a93e786e9a8fbbfaf9a0ea614d6c9ed19ef @satb committed Jan 12, 2014
Showing with 11 additions and 1 deletion.
  1. +11 −1 lib/client.js
View
@@ -87,7 +87,17 @@ function encodeSpecialCharacters(filename, options) {
if(options['no_encoding'] ){
return filename;
}else{
- return encodeURI(filename);
+ /*
+ using js escape is deprecated in ECMA 3.0. encodeURIComponent won't encode single quote
+ use encodeURI when you want to encode the URL
+ use encodeURIComponent when you want to encode parameters etc - So, encoding http://unclepai.com/... will mangle
+ the whole URL - so in this case you have to use encodeURI. However, what we are encoding here is the file name
+ for S3 for example, then we have to use encodeURIComponent so special characters like double quotes, ampersand is taken care of
+ for S3 - spaces are encoded as + - so replace encoded value (%20), with +
+ for S3 - double quotes are double encoded - encode twice - once with encodeURIComponent (gives %22), then encode that again (gives %2522)
+ */
+ return encodeURIComponent(filename).replace("'", '%27').replace(/%20/g, '+').replace(/%22/g, '%2522')
+ //encodeURI(filename);
}
}

0 comments on commit 5af56a9

Please sign in to comment.