Skip to content

Commit

Permalink
fix !'()* url encode error
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Jul 13, 2017
1 parent 2819843 commit 04e4df8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ var xml2js = require('xml2js');
var xmlParser = new xml2js.Parser({explicitArray: false, ignoreAttrs: true});
var xmlBuilder = new xml2js.Builder();

function camSafeUrlEncode(str) {
return encodeURIComponent(str)
.replace(/!/g, '%21')
.replace(/'/g, '%27')
.replace(/\(/g, '%28')
.replace(/\)/g, '%29')
.replace(/\*/g, '%2A');
}

//测试用的key后面可以去掉
var getAuth = function (opt) {
Expand Down Expand Up @@ -40,8 +48,8 @@ var getAuth = function (opt) {
key = keyList[i];
val = obj[key] || '';
key = key.toLowerCase();
key = encodeURIComponent(key);
list.push(key + '=' + encodeURIComponent(val));
key = camSafeUrlEncode(key);
list.push(key + '=' + camSafeUrlEncode(val));
}
return list.join('&');
};
Expand Down

0 comments on commit 04e4df8

Please sign in to comment.