Skip to content

Incorrect absoluteString for URL on linux #72702

Open
@Jomy10

Description

@Jomy10

Description

URL(fileURLWithPath: "images", isDirectory: true).absoluteString returns file:///home/..../images

This is a problem because when running FileManager.default.contentsOfDirectory(atPath: url.absoluteString) for example, it will throw an error saying the file does not exist.

Reproduction

let url = URL(fileURLWithPath: "images", isDirectory: true)
print("absoluteString: \(url.absoluteString)")
do {
  try FileManager.default.contentsOfDirectory(atPath: url.absoluteString)
} catch {
  print("error: \(error)"
}

Expected behavior

absoluteString should return /home/..../images, not file:///home/..../images

Environment

Swift version 5.10 (swift-5.10-RELEASE)
Target: aarch64-unknown-linux-gnu

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    FoundationLinuxPlatform: LinuxbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.transfer candidateThe issue may belong in another repository

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions