@@ -586,6 +586,42 @@ final class URLTests : XCTestCase {
586
586
XCTAssertEqual ( url. fileSystemPath, " /path/slashes " )
587
587
}
588
588
589
+ func testURLNotDirectoryHintStripsTrailingSlash( ) throws {
590
+ // Supply a path with a trailing slash but say it's not a direcotry
591
+ var url = URL ( filePath: " /path/ " , directoryHint: . notDirectory)
592
+ XCTAssertFalse ( url. hasDirectoryPath)
593
+ XCTAssertEqual ( url. path ( ) , " /path " )
594
+
595
+ url = URL ( fileURLWithPath: " /path/ " , isDirectory: false )
596
+ XCTAssertFalse ( url. hasDirectoryPath)
597
+ XCTAssertEqual ( url. path ( ) , " /path " )
598
+
599
+ url = URL ( filePath: " /path/// " , directoryHint: . notDirectory)
600
+ XCTAssertFalse ( url. hasDirectoryPath)
601
+ XCTAssertEqual ( url. path ( ) , " /path " )
602
+
603
+ url = URL ( fileURLWithPath: " /path/// " , isDirectory: false )
604
+ XCTAssertFalse ( url. hasDirectoryPath)
605
+ XCTAssertEqual ( url. path ( ) , " /path " )
606
+
607
+ // With .checkFileSystem, don't modify the path for a non-existent file
608
+ url = URL ( filePath: " /my/non/existent/path/ " , directoryHint: . checkFileSystem)
609
+ XCTAssertTrue ( url. hasDirectoryPath)
610
+ XCTAssertEqual ( url. path ( ) , " /my/non/existent/path/ " )
611
+
612
+ url = URL ( fileURLWithPath: " /my/non/existent/path/ " )
613
+ XCTAssertTrue ( url. hasDirectoryPath)
614
+ XCTAssertEqual ( url. path ( ) , " /my/non/existent/path/ " )
615
+
616
+ url = URL ( filePath: " /my/non/existent/path " , directoryHint: . checkFileSystem)
617
+ XCTAssertFalse ( url. hasDirectoryPath)
618
+ XCTAssertEqual ( url. path ( ) , " /my/non/existent/path " )
619
+
620
+ url = URL ( fileURLWithPath: " /my/non/existent/path " )
621
+ XCTAssertFalse ( url. hasDirectoryPath)
622
+ XCTAssertEqual ( url. path ( ) , " /my/non/existent/path " )
623
+ }
624
+
589
625
func testURLComponentsPercentEncodedUnencodedProperties( ) throws {
590
626
var comp = URLComponents ( )
591
627
0 commit comments