mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
fix realpath behavior in windows (#3425)
This commit is contained in:
parent
81efa9d938
commit
537c6b3ed9
2 changed files with 15 additions and 3 deletions
|
@ -4,7 +4,11 @@ import { testPerm, assert, assertEquals } from "./test_util.ts";
|
|||
testPerm({ read: true }, function realpathSyncSuccess(): void {
|
||||
const incompletePath = "cli/tests/fixture.json";
|
||||
const realPath = Deno.realpathSync(incompletePath);
|
||||
assert(realPath.startsWith("/"));
|
||||
if (Deno.build.os !== "win") {
|
||||
assert(realPath.startsWith("/"));
|
||||
} else {
|
||||
assert(/^[A-Z]/.test(realPath));
|
||||
}
|
||||
assert(realPath.endsWith(incompletePath));
|
||||
});
|
||||
|
||||
|
@ -47,7 +51,11 @@ testPerm({ read: true }, function realpathSyncNotFound(): void {
|
|||
testPerm({ read: true }, async function realpathSuccess(): Promise<void> {
|
||||
const incompletePath = "cli/tests/fixture.json";
|
||||
const realPath = await Deno.realpath(incompletePath);
|
||||
assert(realPath.startsWith("/"));
|
||||
if (Deno.build.os !== "win") {
|
||||
assert(realPath.startsWith("/"));
|
||||
} else {
|
||||
assert(/^[A-Z]/.test(realPath));
|
||||
}
|
||||
assert(realPath.endsWith(incompletePath));
|
||||
});
|
||||
|
||||
|
|
|
@ -300,7 +300,11 @@ fn op_realpath(
|
|||
// corresponds to the realpath on Unix and
|
||||
// CreateFile and GetFinalPathNameByHandle on Windows
|
||||
let realpath = fs::canonicalize(&path)?;
|
||||
let realpath_str = realpath.to_str().unwrap().to_owned().replace("\\", "/");
|
||||
let mut realpath_str =
|
||||
realpath.to_str().unwrap().to_owned().replace("\\", "/");
|
||||
if cfg!(windows) {
|
||||
realpath_str = realpath_str.trim_start_matches("//?/").to_string();
|
||||
}
|
||||
Ok(json!(realpath_str))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue