apple / apple/swift-system

Surprising behavior on Windows with drive roots in the middle of a path

Open
#188 2 comments 0 reactions 1 assignee Claimed by @jrflat View on GitHub
Windows
Dominant language
Swift
Stars
1.4k
Forks
154
PR merge metrics
No merged PRs in 30d

Description

Consider the following (tested with v1.3.1 tag):

```swift
let fp = FilePath("Sources/E:\\source")
print(fp.isAbsolute) // false
print(fp.isRelative) // true
print(fp.root) // nil
print(Array(fp.components)) // ["Sources", "E:", "source"]

print(FilePath("Sources").appending(fp.components)) // SystemPackage/FilePathParsing.swift:351: Assertion failed
print(FilePath("Sources").pushing(fp)) // Sources\Sources\E:\source

print(FilePath("Sources").appending(FilePath.Component("C:"))) // SystemPackage/FilePathString.swift:299: Fatal error: FilePath.Component must be created from exactly one non-root component
print(FilePath("Sources").appending("C:")) // Sources
```

It's not clear to me that some of these assertions are expected, or even how a seemingly bogus path like `Sources/E:\\source` _should_ be treated by the APIs. Should the FilePath constructor have asserted right away on this path if containing prohibited characters per https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions? Should there be an alternative validating constructor that returns nil or throws in this case?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.