Skip to content

Commit 6bf5c90

Browse files
authored
(141256674) Add compatibility check for malformed URL(filePath:) input (#1097)
1 parent 0b4f13f commit 6bf5c90

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Sources/FoundationEssentials/URL/URL.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,17 @@ extension URL {
22392239
var filePath = path
22402240
#endif
22412241

2242+
#if FOUNDATION_FRAMEWORK
2243+
// Linked-on-or-after check for apps which incorrectly pass a full
2244+
// "file:" URL string. In the old implementation, this could work
2245+
// rarely if the app immediately called .appendingPathComponent(_:),
2246+
// which used to accidentally interpret a relative string starting
2247+
// with "file:" as an absolute file URL string.
2248+
if Self.compatibility3 && filePath.starts(with: "file:") {
2249+
filePath = String(filePath.dropFirst(5))
2250+
}
2251+
#endif
2252+
22422253
let isAbsolute = URL.isAbsolute(standardizing: &filePath)
22432254

22442255
#if !NO_FILESYSTEM

0 commit comments

Comments
 (0)