@@ -514,6 +514,46 @@ final class URLTests : XCTestCase {
514
514
}
515
515
}
516
516
517
+ func testURLAppendingPathDoesNotEncodeColon( ) throws {
518
+ let baseURL = URL ( string: " file:///var/mobile/ " ) !
519
+ let url = URL ( string: " relative " , relativeTo: baseURL) !
520
+ let component = " no:slash "
521
+ let slashComponent = " /with:slash "
522
+
523
+ // Make sure we don't encode ":" since `component` is not the first path segment
524
+ var appended = url. appending ( path: component, directoryHint: . notDirectory)
525
+ XCTAssertEqual ( appended. absoluteString, " file:///var/mobile/relative/no:slash " )
526
+ XCTAssertEqual ( appended. relativePath, " relative/no:slash " )
527
+
528
+ appended = url. appending ( path: slashComponent, directoryHint: . notDirectory)
529
+ XCTAssertEqual ( appended. absoluteString, " file:///var/mobile/relative/with:slash " )
530
+ XCTAssertEqual ( appended. relativePath, " relative/with:slash " )
531
+
532
+ appended = url. appending ( component: component, directoryHint: . notDirectory)
533
+ XCTAssertEqual ( appended. absoluteString, " file:///var/mobile/relative/no:slash " )
534
+ XCTAssertEqual ( appended. relativePath, " relative/no:slash " )
535
+
536
+ // `appending(component:)` should explicitly treat `component` as a single
537
+ // path component, meaning "/" should be encoded to "%2F" before appending
538
+ appended = url. appending ( component: slashComponent, directoryHint: . notDirectory)
539
+ #if FOUNDATION_FRAMEWORK_NSURL
540
+ XCTAssertEqual ( appended. absoluteString, " file:///var/mobile/relative/with:slash " )
541
+ XCTAssertEqual ( appended. relativePath, " relative/with:slash " )
542
+ #else
543
+ XCTAssertEqual ( appended. absoluteString, " file:///var/mobile/relative/%2Fwith:slash " )
544
+ XCTAssertEqual ( appended. relativePath, " relative/%2Fwith:slash " )
545
+ #endif
546
+
547
+ appended = url. appendingPathComponent ( component, isDirectory: false )
548
+ XCTAssertEqual ( appended. absoluteString, " file:///var/mobile/relative/no:slash " )
549
+ XCTAssertEqual ( appended. relativePath, " relative/no:slash " )
550
+
551
+ // Test deprecated API, which acts like `appending(path:)`
552
+ appended = url. appendingPathComponent ( slashComponent, isDirectory: false )
553
+ XCTAssertEqual ( appended. absoluteString, " file:///var/mobile/relative/with:slash " )
554
+ XCTAssertEqual ( appended. relativePath, " relative/with:slash " )
555
+ }
556
+
517
557
func testURLComponentsPercentEncodedUnencodedProperties( ) throws {
518
558
var comp = URLComponents ( )
519
559
0 commit comments