Created
February 16, 2014 07:40
-
-
Save StuPig/9030707 to your computer and use it in GitHub Desktop.
转换为标准路径
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 路径转换为标准路径 | |
* @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