-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Correctly normalize UNC paths #6041
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -388,21 +388,27 @@ define(function (require, exports, module) { | |
return (fullPath[0] === "/" || fullPath[1] === ":"); | ||
}; | ||
|
||
// Matches continguous groups of forward slashes | ||
var _duplicatedSlashRE = /\/{2,}/g; | ||
|
||
/** | ||
* Returns a canonical version of the path: no duplicated "/"es, no ".."s, | ||
* and directories guaranteed to end in a trailing "/" | ||
* @param {!string} path Absolute path, using "/" as path separator | ||
* @param {boolean=} isDirectory | ||
* @return {!string} | ||
*/ | ||
function _normalizePath(path, isDirectory) { | ||
FileSystem.prototype._normalizePath = function (path, isDirectory) { | ||
|
||
if (!FileSystem.isAbsolutePath(path)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess isAbsolutePath() still works on the UNC path by misinterpreting it as a Unix-style path. But at some point I still think we should generalize the current normalizeUNCPaths flag into a handleWindowsPaths flag that both enabled the UNC path handling and disables the ":" check in isAbsolutePath()... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, we could do that. Does it really buy us anything right now though? |
||
throw new Error("Paths must be absolute: '" + path + "'"); // expect only absolute paths | ||
} | ||
|
||
|
||
var normalizeUNCPaths = this._impl && this._impl.normalizeUNCPaths, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a bug if we get called while There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is at least one group of instances of this that didn't seem crazy to me: In JSUtils-tests.js, there are calls to |
||
isUNCPath = normalizeUNCPaths && path.search(_duplicatedSlashRE) === 0; | ||
|
||
// Remove duplicated "/"es | ||
path = path.replace(/\/{2,}/g, "/"); | ||
path = path.replace(_duplicatedSlashRE, "/"); | ||
|
||
// Remove ".." segments | ||
if (path.indexOf("..") !== -1) { | ||
|
@@ -427,8 +433,13 @@ define(function (require, exports, module) { | |
} | ||
} | ||
|
||
if (isUNCPath) { | ||
// Restore the leading double slash that was removed previously | ||
path = "/" + path; | ||
} | ||
|
||
return path; | ||
} | ||
}; | ||
|
||
/** | ||
* Return a File object for the specified path. | ||
|
@@ -438,7 +449,7 @@ define(function (require, exports, module) { | |
* @return {File} The File object. This file may not yet exist on disk. | ||
*/ | ||
FileSystem.prototype.getFileForPath = function (path) { | ||
path = _normalizePath(path, false); | ||
path = this._normalizePath(path, false); | ||
var file = this._index.getEntry(path); | ||
|
||
if (!file) { | ||
|
@@ -457,7 +468,7 @@ define(function (require, exports, module) { | |
* @return {Directory} The Directory object. This directory may not yet exist on disk. | ||
*/ | ||
FileSystem.prototype.getDirectoryForPath = function (path) { | ||
path = _normalizePath(path, true); | ||
path = this._normalizePath(path, true); | ||
var directory = this._index.getEntry(path); | ||
|
||
if (!directory) { | ||
|
@@ -579,7 +590,7 @@ define(function (require, exports, module) { | |
return; | ||
} | ||
|
||
path = _normalizePath(path, false); | ||
path = this._normalizePath(path, false); | ||
var entry = this._index.getEntry(path); | ||
|
||
if (entry) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to name this all-upercase and add
@const
tag in docsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.