Skip to content

Appending to an empty file path results in an absolute path #921

Closed
@omochi

Description

@omochi

Problematic Code:

import Foundation

let dir = URL(fileURLWithPath: "")
print(dir.path) // => /tmp/ee78646dddfd6304
let file = dir.appendingPathComponent("main.swift")
print(file.path) // => /main.swift

As shown in the example, even though dir holds the path to the current directory, appending a file to it results in an absolute path starting with a slash. This behavior is unexpected because appending to a current directory URL should ideally maintain a relative path, not convert it to an absolute one.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions