Bug 960962 - OS.File normalization and concatenation issues on Windows. r=Yoric

This commit is contained in:
Paolo Amadini 2014-02-10 19:59:29 +01:00
Родитель d59f3ed27d
Коммит 6c534820ae
3 изменённых файлов: 16 добавлений и 9 удалений

Просмотреть файл

@ -142,7 +142,6 @@ let join = function(...path) {
let absolute = false; let absolute = false;
for each(let subpath in path) { for each(let subpath in path) {
let drive = this.winGetDrive(subpath); let drive = this.winGetDrive(subpath);
let abs = this.winIsAbsolute(subpath);
if (drive) { if (drive) {
root = drive; root = drive;
let component = trimBackslashes(subpath.slice(drive.length)); let component = trimBackslashes(subpath.slice(drive.length));
@ -151,8 +150,8 @@ let join = function(...path) {
} else { } else {
paths = []; paths = [];
} }
absolute = abs; absolute = true;
} else if (abs) { } else if (this.winIsAbsolute(subpath)) {
paths = [trimBackslashes(subpath)]; paths = [trimBackslashes(subpath)];
absolute = true; absolute = true;
} else { } else {
@ -259,7 +258,7 @@ let normalize = function(path) {
// Put everything back together // Put everything back together
let result = stack.join("\\"); let result = stack.join("\\");
if (absolute) { if (absolute || root) {
result = "\\" + result; result = "\\" + result;
} }
if (root) { if (root) {

Просмотреть файл

@ -89,8 +89,11 @@ function run_test() {
let uri = Services.io.newFileURI(file).spec; let uri = Services.io.newFileURI(file).spec;
do_check_eq(uri, OS.Path.toFileURI(path)); do_check_eq(uri, OS.Path.toFileURI(path));
// keep the resulting URI to try the reverse // keep the resulting URI to try the reverse, except for "C:\" for which the
uris.push(uri) // behavior of nsIFileURL and OS.File is inconsistent
if (path != "C:\\") {
uris.push(uri);
}
} }
for (let uri of uris) { for (let uri of uris) {

Просмотреть файл

@ -68,19 +68,23 @@ function run_test()
do_check_eq(Win.dirname("c:a\\b\\", options), "a\\b"); do_check_eq(Win.dirname("c:a\\b\\", options), "a\\b");
do_check_eq(Win.dirname("c:a\\\\\\\\b", options), "a"); do_check_eq(Win.dirname("c:a\\\\\\\\b", options), "a");
do_check_eq(Win.dirname("c:abc", options), "."); do_check_eq(Win.dirname("c:abc", options), ".");
do_check_eq(Win.join("c:", "abc"), "c:\\abc", "join c:,abc");
do_check_eq(Win.normalize("c:"), "c:\\");
do_check_eq(Win.normalize("c:\\"), "c:\\");
do_check_eq(Win.normalize("c:\\a\\b\\c"), "c:\\a\\b\\c"); do_check_eq(Win.normalize("c:\\a\\b\\c"), "c:\\a\\b\\c");
do_check_eq(Win.normalize("c:\\a\\b\\\\\\\\c"), "c:\\a\\b\\c"); do_check_eq(Win.normalize("c:\\a\\b\\\\\\\\c"), "c:\\a\\b\\c");
do_check_eq(Win.normalize("c:\\\\\\\\a\\b\\c"), "c:\\a\\b\\c"); do_check_eq(Win.normalize("c:\\\\\\\\a\\b\\c"), "c:\\a\\b\\c");
do_check_eq(Win.normalize("c:\\a\\b\\c\\\\\\"), "c:\\a\\b\\c"); do_check_eq(Win.normalize("c:\\a\\b\\c\\\\\\"), "c:\\a\\b\\c");
do_check_eq(Win.normalize("c:\\a\\b\\c\\..\\..\\..\\d\\e\\f"), "c:\\d\\e\\f"); do_check_eq(Win.normalize("c:\\a\\b\\c\\..\\..\\..\\d\\e\\f"), "c:\\d\\e\\f");
do_check_eq(Win.normalize("c:a\\b\\c\\..\\..\\..\\d\\e\\f"), "c:d\\e\\f"); do_check_eq(Win.normalize("c:a\\b\\c\\..\\..\\..\\d\\e\\f"), "c:\\d\\e\\f");
do_check_fail(function() Win.normalize("c:\\a\\b\\c\\..\\..\\..\\..\\d\\e\\f")); do_check_fail(function() Win.normalize("c:\\a\\b\\c\\..\\..\\..\\..\\d\\e\\f"));
do_check_eq(Win.join("c:\\", "foo"), "c:\\foo", "join c:\,foo");
do_check_eq(Win.join("c:\\tmp", "foo", "bar"), "c:\\tmp\\foo\\bar", "join c:\\tmp,foo,bar"); do_check_eq(Win.join("c:\\tmp", "foo", "bar"), "c:\\tmp\\foo\\bar", "join c:\\tmp,foo,bar");
do_check_eq(Win.join("c:\\tmp", "\\foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,\\foo,bar"); do_check_eq(Win.join("c:\\tmp", "\\foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,\\foo,bar");
do_check_eq(Win.join("c:\\tmp", "c:\\foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,c:\\foo,bar"); do_check_eq(Win.join("c:\\tmp", "c:\\foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,c:\\foo,bar");
do_check_eq(Win.join("c:\\tmp", "c:foo", "bar"), "c:foo\\bar", "join c:\\tmp,c:foo,bar"); do_check_eq(Win.join("c:\\tmp", "c:foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,c:foo,bar");
do_check_eq(Win.winGetDrive("c:"), "c:"); do_check_eq(Win.winGetDrive("c:"), "c:");
do_check_eq(Win.winGetDrive("c:\\"), "c:"); do_check_eq(Win.winGetDrive("c:\\"), "c:");
do_check_eq(Win.winGetDrive("c:abc"), "c:"); do_check_eq(Win.winGetDrive("c:abc"), "c:");
@ -96,12 +100,13 @@ function run_test()
do_check_eq(Win.normalize("a/b/c/../../../d/e/f"), "d\\e\\f"); do_check_eq(Win.normalize("a/b/c/../../../d/e/f"), "d\\e\\f");
do_print("Forwardslash-separated, with a drive"); do_print("Forwardslash-separated, with a drive");
do_check_eq(Win.normalize("c:/"), "c:\\");
do_check_eq(Win.normalize("c:/a/b/c"), "c:\\a\\b\\c"); do_check_eq(Win.normalize("c:/a/b/c"), "c:\\a\\b\\c");
do_check_eq(Win.normalize("c:/a/b////c"), "c:\\a\\b\\c"); do_check_eq(Win.normalize("c:/a/b////c"), "c:\\a\\b\\c");
do_check_eq(Win.normalize("c:////a/b/c"), "c:\\a\\b\\c"); do_check_eq(Win.normalize("c:////a/b/c"), "c:\\a\\b\\c");
do_check_eq(Win.normalize("c:/a/b/c///"), "c:\\a\\b\\c"); do_check_eq(Win.normalize("c:/a/b/c///"), "c:\\a\\b\\c");
do_check_eq(Win.normalize("c:/a/b/c/../../../d/e/f"), "c:\\d\\e\\f"); do_check_eq(Win.normalize("c:/a/b/c/../../../d/e/f"), "c:\\d\\e\\f");
do_check_eq(Win.normalize("c:a/b/c/../../../d/e/f"), "c:d\\e\\f"); do_check_eq(Win.normalize("c:a/b/c/../../../d/e/f"), "c:\\d\\e\\f");
do_print("Backslash-separated, UNC-style"); do_print("Backslash-separated, UNC-style");
do_check_eq(Win.basename("\\\\a\\b"), "b"); do_check_eq(Win.basename("\\\\a\\b"), "b");