Skip to content

Instantly share code, notes, and snippets.

@StuPig
Created February 16, 2014 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StuPig/9030707 to your computer and use it in GitHub Desktop.
Save StuPig/9030707 to your computer and use it in GitHub Desktop.
转换为标准路径
/**
* 路径转换为标准路径
* @param path
* @return {String|XML}
*/
getRealPath: function (path) {
var DOT_RE = /\/\.\//g,
DOUBLE_DOT_RE = /\/[^\/]+\/\.\.\//;
// /a/b/./c/./d ==> /a/b/c/d
path = path.replace(DOT_RE, "/");
// a/b/c/../../d ==> a/b/../d ==> a/d
while (path.match(DOUBLE_DOT_RE)) {
path = path.replace(DOUBLE_DOT_RE, "/");
}
return path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment