Skip to content
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

Odd result from Path::components on Windows #101358

Closed
casey opened this issue Sep 3, 2022 · 1 comment · Fixed by #101366
Closed

Odd result from Path::components on Windows #101358

casey opened this issue Sep 3, 2022 · 1 comment · Fixed by #101366
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows

Comments

@casey
Copy link
Contributor

casey commented Sep 3, 2022

This might be a bug, or this might just be me not understanding how Windows UNC paths work.

When I call this:

Path::new("//foo//bar//").components().collect::<Vec<Component>>()

I get:

[Prefix(PrefixComponent { raw: "//foo//ba", parsed: UNC("foo", "bar") }), RootDir, Normal("r")]

This seems very odd! The bar component is truncated, and //foo/ba is the prefix, followed by a root dir, followed a normal r component.

It seems like the way this path is broken into components on Windows has changed since an old release. I have a path cleaning library, lexiclean, whose CI was passing as of April 20th. It picked up a new release between now and then, and CI is now failing.

@casey casey added the C-bug Category: This is a bug. label Sep 3, 2022
@ChrisDenton ChrisDenton added the O-windows Operating system: Windows label Sep 3, 2022
@ChrisDenton
Copy link
Member

This is indeed a bug. But it's also a bit of an edge case. It's not entirely obvious what the correct behaviour should be as technically speaking it's not a well formed path. The prefix is one place where Windows (sometimes) cares about the number and type of slashes.

Anyway, the old behaviour was:

[RootDir, Normal("foo"), Normal("bar")]

Which is also wrong (it changes the prefix type), but maybe less wrong than it currently is.

Perhaps the best we could do is:

[Prefix(PrefixComponent { raw: "//foo", parsed: UNC("foo", "") }), RootDir, Normal("bar")]

Which at least preserves the root.

Ideally it would be:

[Prefix(PrefixComponent { raw: "//foo//bar", parsed: UNC("foo", "bar") }), RootDir]

But currently we require the prefix length to be able to be recomputed from the parsed parts so this isn't currently possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants