Skip to content

Commit

Permalink
Improved logic of cc.path._normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
pandamicro committed Aug 24, 2015
1 parent c5453ed commit 24f068d
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions CCBoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ cc.async = /** @lends cc.async# */{
* @class
*/
cc.path = /** @lends cc.path# */{
normalizeRE: /[^\.\/]+\/\.\.\//,

/**
* Join strings to be a path.
* @example
Expand Down Expand Up @@ -502,21 +504,15 @@ cc.path = /** @lends cc.path# */{
index = index <= 0 ? 0 : index + 1;
return pathStr.substring(0, index) + basename + ext + tempStr;
},
//todo Open up after verification
//todo make public after verification
_normalize: function(url){
url = String(url);
var status = true;
var repFunc = function(){
status = true;
return "";
};
//remove ../
while(status){
status = false;
url = url.replace(/[^\.\/]+\/\.\.\//, repFunc);
}
//remove ./
url = url.replace(/\/\.\//g, "/");
var oldUrl = url = String(url);

//removing all ../
do {
oldUrl = url;
url = url.replace(this.normalizeRE, "");
} while(oldUrl.length !== url.length);
return url;
}
};
Expand Down

0 comments on commit 24f068d

Please sign in to comment.