Appending to an empty file path results in an absolute path
Closed this issue · 0 comments
omochi commented
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.