Skip to content

Conversation

@daveinglis
Copy link
Contributor

  • there where a couple case where relative(to:) would assert on windows when a path was long (>260) and when tailing slashes where not removed in some cases.

@daveinglis
Copy link
Contributor Author

@swift-ci test

@daveinglis
Copy link
Contributor Author

@swift-ci test linux

while !substring.isEmpty && substring.utf8.last == UInt8(ascii: "\\") {
substring = substring.dropLast()
}
if !substring.isEmpty && substring.last != ":" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kinda sketchy. The last character being : could be a malformed path, e.g. C:\file.txt:.

if !substring.isEmpty && substring.last != ":" {
// Drop the trailing '\', unless the string path only
// has '\', and unless the slashes are right after the drive letter.
path = String(substring)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm - C: and C:\ have completely different meanings. Is this logic preserving the trailing slash in the case where the path is pointing at a drive root?

@daveinglis daveinglis force-pushed the fix_asserts branch 2 times, most recently from 975683d to df81ada Compare December 16, 2025 18:29
@jakepetroules
Copy link
Contributor

@swift-ci test

@daveinglis
Copy link
Contributor Author

@swift-ci test windows

@daveinglis daveinglis marked this pull request as draft December 17, 2025 21:31
@daveinglis
Copy link
Contributor Author

This needs some more work/investigation, seeing some strange crashes in swiftPM that this is causing

…ssert

- there where a couple case where relative(to:) would assert on windows
  when a path was long (>206) and when tailing slashes where not removed
  in some cases.
@daveinglis
Copy link
Contributor Author

@swift-ci test

@daveinglis
Copy link
Contributor Author

@swift-ci test windows

1 similar comment
@daveinglis
Copy link
Contributor Author

@swift-ci test windows

@daveinglis daveinglis marked this pull request as ready for review December 18, 2025 14:59
@daveinglis
Copy link
Contributor Author

@swift-ci test

if string.first?.isASCII ?? false, string.first?.isLetter ?? false, string.first?.isLowercase ?? false,
let path: String
let hasDrive: Bool
if string.first?.isASCII ?? false, string.first?.isLetter ?? false,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (possibly-blocking): Does not account for long path.

This does not take into account long path \\?\D:\<very long path>. Can we instead use Regex to determine if the passed string matches the desired conditions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it not supporting that is fine. Foundation does go to some lengths to ensure that long paths are transparent to the user (it converts on the way in and out). Users generally would not type the NT path (and you cannot copy it from explorer as that transacts in Win32 paths and cmd would rely on DOS paths).

return self == .root ? self : Self(string: dirname)
}

init(string: String) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (blocking): Can we augment the automated tests to ensure the defect is fixed, and that we won't regress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants