mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
fix(cli/ops/fs): Don't force Windows paths separate paths with forward slash (#7833)
This commit is contained in:
parent
99aa23b8dd
commit
c226d3af25
2 changed files with 25 additions and 22 deletions
|
@ -941,10 +941,9 @@ fn op_realpath_sync(
|
|||
// corresponds to the realpath on Unix and
|
||||
// CreateFile and GetFinalPathNameByHandle on Windows
|
||||
let realpath = std::fs::canonicalize(&path)?;
|
||||
let mut realpath_str =
|
||||
into_string(realpath.into_os_string())?.replace("\\", "/");
|
||||
let mut realpath_str = into_string(realpath.into_os_string())?;
|
||||
if cfg!(windows) {
|
||||
realpath_str = realpath_str.trim_start_matches("//?/").to_string();
|
||||
realpath_str = realpath_str.trim_start_matches("\\\\?\\").to_string();
|
||||
}
|
||||
Ok(json!(realpath_str))
|
||||
}
|
||||
|
@ -971,10 +970,9 @@ async fn op_realpath_async(
|
|||
// corresponds to the realpath on Unix and
|
||||
// CreateFile and GetFinalPathNameByHandle on Windows
|
||||
let realpath = std::fs::canonicalize(&path)?;
|
||||
let mut realpath_str =
|
||||
into_string(realpath.into_os_string())?.replace("\\", "/");
|
||||
let mut realpath_str = into_string(realpath.into_os_string())?;
|
||||
if cfg!(windows) {
|
||||
realpath_str = realpath_str.trim_start_matches("//?/").to_string();
|
||||
realpath_str = realpath_str.trim_start_matches("\\\\?\\").to_string();
|
||||
}
|
||||
Ok(json!(realpath_str))
|
||||
})
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import {
|
||||
assert,
|
||||
assertMatch,
|
||||
assertThrows,
|
||||
assertThrowsAsync,
|
||||
unitTest,
|
||||
} from "./test_util.ts";
|
||||
|
||||
unitTest({ perms: { read: true } }, function realPathSyncSuccess(): void {
|
||||
const incompletePath = "cli/tests/fixture.json";
|
||||
const realPath = Deno.realPathSync(incompletePath);
|
||||
const relative = "cli/tests/fixture.json";
|
||||
const realPath = Deno.realPathSync(relative);
|
||||
if (Deno.build.os !== "windows") {
|
||||
assert(realPath.startsWith("/"));
|
||||
assert(realPath.endsWith(relative));
|
||||
} else {
|
||||
assert(/^[A-Z]/.test(realPath));
|
||||
assertMatch(realPath, /^[A-Z]:\\/);
|
||||
assert(realPath.endsWith(relative.replace(/\//g, "\\")));
|
||||
}
|
||||
assert(realPath.endsWith(incompletePath));
|
||||
});
|
||||
|
||||
unitTest(
|
||||
|
@ -27,13 +29,14 @@ unitTest(
|
|||
const symlink = testDir + "/symln";
|
||||
Deno.mkdirSync(target);
|
||||
Deno.symlinkSync(target, symlink);
|
||||
const targetPath = Deno.realPathSync(symlink);
|
||||
const realPath = Deno.realPathSync(symlink);
|
||||
if (Deno.build.os !== "windows") {
|
||||
assert(targetPath.startsWith("/"));
|
||||
assert(realPath.startsWith("/"));
|
||||
assert(realPath.endsWith("/target"));
|
||||
} else {
|
||||
assert(/^[A-Z]/.test(targetPath));
|
||||
assertMatch(realPath, /^[A-Z]:\\/);
|
||||
assert(realPath.endsWith("\\target"));
|
||||
}
|
||||
assert(targetPath.endsWith("/target"));
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -52,14 +55,15 @@ unitTest({ perms: { read: true } }, function realPathSyncNotFound(): void {
|
|||
unitTest({ perms: { read: true } }, async function realPathSuccess(): Promise<
|
||||
void
|
||||
> {
|
||||
const incompletePath = "cli/tests/fixture.json";
|
||||
const realPath = await Deno.realPath(incompletePath);
|
||||
const relativePath = "cli/tests/fixture.json";
|
||||
const realPath = await Deno.realPath(relativePath);
|
||||
if (Deno.build.os !== "windows") {
|
||||
assert(realPath.startsWith("/"));
|
||||
assert(realPath.endsWith(relativePath));
|
||||
} else {
|
||||
assert(/^[A-Z]/.test(realPath));
|
||||
assertMatch(realPath, /^[A-Z]:\\/);
|
||||
assert(realPath.endsWith(relativePath.replace(/\//g, "\\")));
|
||||
}
|
||||
assert(realPath.endsWith(incompletePath));
|
||||
});
|
||||
|
||||
unitTest(
|
||||
|
@ -72,13 +76,14 @@ unitTest(
|
|||
const symlink = testDir + "/symln";
|
||||
Deno.mkdirSync(target);
|
||||
Deno.symlinkSync(target, symlink);
|
||||
const targetPath = await Deno.realPath(symlink);
|
||||
const realPath = await Deno.realPath(symlink);
|
||||
if (Deno.build.os !== "windows") {
|
||||
assert(targetPath.startsWith("/"));
|
||||
assert(realPath.startsWith("/"));
|
||||
assert(realPath.endsWith("/target"));
|
||||
} else {
|
||||
assert(/^[A-Z]/.test(targetPath));
|
||||
assertMatch(realPath, /^[A-Z]:\\/);
|
||||
assert(realPath.endsWith("\\target"));
|
||||
}
|
||||
assert(targetPath.endsWith("/target"));
|
||||
},
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue