-
-
Notifications
You must be signed in to change notification settings - Fork 26
fix: properly handle DOS device paths in strip_windows_prefix #455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is what I put together from the stackoverflow answer: /// When applicable, converts a [DOS device path](https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths)
/// to a normal path (usually, "Traditional DOS paths" or "UNC path") that can be consumed by the `import`/`require` syntax of Node.js.
/// i.e. Remove `\\?\`, `\\.\` prefix then `\\?\UNC` prefix.
/// Code adapted from <https://stackoverflow.com/questions/50322817/how-do-i-remove-the-prefix-from-a-canonical-windows-path>
#[cfg(target_os = "windows")]
#[inline]
pub fn dunce(p: PathBuf) -> PathBuf {
let p = p.strip_prefix(r#"\\?\"#).map(|p| p.to_path_buf()).unwrap_or(p);
let p = p.strip_prefix(r#"\\.\"#).map(|p| p.to_path_buf()).unwrap_or(p);
dunce::simplified(&p).to_path_buf()
} |
CodSpeed Performance ReportMerging #455 will not alter performanceComparing Summary
|
I think the tricky part is, node JS cannot handle imports from either of these paths (even though ordinary fs operations still work). r"\\?\Volume{c8ec34d8-3ba6-45c3-9b9d-3e4148e12d00}\file4.txt"
r"\\?\BootPartition\file4.txt" In these cases, we might need to keep the symlink as-is, and that's what I was trying to describe in #454, which is to prevent resolving (or following the link target of)
into
because NodeJS cannot import from the second path, but it can import from the first path. That's also why I'm letting Probably you can check whether the |
btw we might need to strip the This case might not have been handled by https://gitlab.com/kornelski/dunce/-/blob/master/src/lib.rs?ref_type=heads#L180-182 I've just given the following module path a try
While we cannot represent the path above as a "valid" traditional DOS path, because the length of Welcome to Node.js v22.7.0.
Type ".help" for more information.
> require("D:\\test\\long long long long path\\long long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long path\\test test test test test.js")
{}
> await import("file:///D:\\test\\long long long long path\\long long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long path\\test test test test test.js")
[Module: null prototype] { default: {} }
> require("\\\\?\\D:\\test\\long long long long path\\long long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long pathlong long long long path\\test test test test test.js")
{}
// I couldn't figure out a valid `file:///` URI with DOS device path (\\?\...) to use `await import`. |
I'll come back to this PR when I get the time. |
Please take your time. However, I think my version should be a practically working one, which might be a good place to get started, before we receive other feedbacks in the long run. |
@chenxinyanc I think you can PR to |
Thanks @JounQin ! I'll cherry-pick the PR and probably we can see how it turns out in |
e8a11841083164401bca72841d8c9b2d8f04185d strip_windows_prefix: Handle DOS device paths properly. 2862145da2685b3365e0bfaafdd23751abec2858 [autofix.ci] apply automated fixes 70f675e01bfc780c84d443fdf801028b303717fa Fix build break. b6cbd102d0723747a5b3ab5bb1c10664d34249e7 Fix build break.
2a8dcea
to
068bef9
Compare
068bef9
to
d46a428
Compare
Sorry I went too far trying to optimize this thing, reverted my changes and cleaned up the code structure instead. |
## 🤖 New release * `oxc_resolver`: 5.3.0 -> 6.0.0 (⚠ API breaking changes) ### ⚠ `oxc_resolver` breaking changes ```text --- failure inherent_method_missing: pub method removed or renamed --- Description: A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely. ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/inherent_method_missing.ron Failed in: FileSystemOs::strip_windows_prefix, previously in file /tmp/.tmpZFrfKd/oxc_resolver/src/file_system.rs:168 ``` <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [6.0.0](oxc_resolver-v5.3.0...oxc_resolver-v6.0.0) - 2025-04-22 ### <!-- 1 -->Bug Fixes - properly handle DOS device paths in strip_windows_prefix ([#455](#455)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/).
@Boshen Sorry for the flurry but it seems my prior change in this PR is not sufficient to fix my issue: unrs/unrs-resolver#84 (comment) I've just tried the binary built from 5fc3395 in this repo locally and confirmed the same outcome. No need to worry at this point, though. IMO this is not exactly a regression:
Since I've already added some changes today in the downstream PR: unrs/unrs-resolver#84, I will probably open another PR here in
|
Sounds good to me. |
e8a11841083164401bca72841d8c9b2d8f04185d strip_windows_prefix: Handle DOS device paths properly. 2862145da2685b3365e0bfaafdd23751abec2858 [autofix.ci] apply automated fixes 70f675e01bfc780c84d443fdf801028b303717fa Fix build break. b6cbd102d0723747a5b3ab5bb1c10664d34249e7 Fix build break.
…oject/oxc-resolver#455 e8a11841083164401bca72841d8c9b2d8f04185d strip_windows_prefix: Handle DOS device paths properly. 2862145da2685b3365e0bfaafdd23751abec2858 [autofix.ci] apply automated fixes 70f675e01bfc780c84d443fdf801028b303717fa Fix build break. b6cbd102d0723747a5b3ab5bb1c10664d34249e7 Fix build break.
Fixes #454
This PR changed the name and return type of
strip_windows_prefix
totry_strip_windows_prefix
, allowing it to returnNone
to indicate unsupported DOS device paths.Most significantly, symlinks referring to a drive without drive letter, usually accessed via a mount point (Mounted Volume), should not be resolved at all, as nodejs
import
/require
does not support such properly, as of Node 22.This PR also rectified the UNC path resolution to prepend the
"\\"
portion to the path.