@@ -641,11 +641,14 @@ extension _URL {
641641 fromSpan: urlPath. extracting ( inputStart... )
642642 )
643643 } else {
644- // Percent-decode, excluding "%00", "%2F", and "%5C"
644+ // Percent-decode, excluding "%00", "%2F"
645645 guard let decodedLength = URLEncoder . percentDecodeUnchecked (
646646 input: urlPath. extracting ( inputStart... ) ,
647647 output: . init( rebasing: outBuffer [ rootLength... ] ) ,
648- excludingASCII: . windowsPath
648+ // Using .posixPath (not .windowsPath) because URL(string:)
649+ // percent-encodes "\" to "%5C", and clients may expect it
650+ // to return decoded.
651+ excludingASCII: . posixPath
649652 ) else {
650653 return 0
651654 }
@@ -751,11 +754,10 @@ extension _URL {
751754 return " / "
752755 }
753756 let component = path. extracting ( componentRange)
754- #if os( Windows)
755- let mask : PercentDecodingASCIIExclusionMask = isFileURL ? . windowsPath : . none
756- #else
757+ // Note: .windowsPath is not used for Windows here because "\"
758+ // is percent-encoded in URL(string:) initializers, so clients
759+ // may expect it to return decoded.
757760 let mask : PercentDecodingASCIIExclusionMask = isFileURL ? . posixPath : . none
758- #endif
759761 return String ( unsafeUninitializedCapacity: component. count) { buffer in
760762 URLEncoder . percentDecodeUnchecked (
761763 input: component,
0 commit comments