Skip to content

Commit fefa12a

Browse files
committed
[Windows] Fix TestURL/test_URLStrings
Since '|' is a valid character in a url on Windows as implemented by CoreFoundation, on Windows, we should expect that `unescaped|pipe` should be properly parsed. This is hacky, but adds a test case on Windows, and disables it on other platforms and vice versa.
1 parent 1a72fc8 commit fefa12a

File tree

2 files changed

+78
-14
lines changed

2 files changed

+78
-14
lines changed

TestFoundation/Resources/NSURLTestData.plist

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3501,6 +3501,60 @@
35013501
<key>Out-NSResults</key>
35023502
<string>&lt;null url&gt;</string>
35033503
</dict>
3504+
<dict>
3505+
<key>In-Title</key>
3506+
<string>NSURLWithString-parse-absolute-escape-006-Windows</string>
3507+
<key>In-URLCreator</key>
3508+
<string>NSURLWithString</string>
3509+
<key>In-Url</key>
3510+
<string>http://test.com/unescaped|pipe</string>
3511+
<key>Out-NSResults</key>
3512+
<dict>
3513+
<key>absoluteString</key>
3514+
<string>http://test.com/unescaped%7Cpipe</string>
3515+
<key>absoluteURLString</key>
3516+
<string>http://test.com/unescaped%7Cpipe</string>
3517+
<key>baseURLString</key>
3518+
<string>&lt;null&gt;</string>
3519+
<key>deletingLastPathComponent</key>
3520+
<string>http://test.com/</string>
3521+
<key>deletingLastPathExtension</key>
3522+
<string>http://test.com/unescaped%7Cpipe</string>
3523+
<key>fragment</key>
3524+
<string>&lt;null&gt;</string>
3525+
<key>host</key>
3526+
<string>test.com</string>
3527+
<key>isFileURL</key>
3528+
<string>NO</string>
3529+
<key>lastPathComponent</key>
3530+
<string>unescaped|pipe</string>
3531+
<key>password</key>
3532+
<string>&lt;null&gt;</string>
3533+
<key>path</key>
3534+
<string>/unescaped|pipe</string>
3535+
<key>pathComponents</key>
3536+
<array>
3537+
<string>/</string>
3538+
<string>unescaped|pipe</string>
3539+
</array>
3540+
<key>pathExtension</key>
3541+
<string></string>
3542+
<key>port</key>
3543+
<string>&lt;null&gt;</string>
3544+
<key>query</key>
3545+
<string>&lt;null&gt;</string>
3546+
<key>relativePath</key>
3547+
<string>/unescaped|pipe</string>
3548+
<key>relativeString</key>
3549+
<string>http://test.com/unescaped%7Cpipe</string>
3550+
<key>scheme</key>
3551+
<string>http</string>
3552+
<key>standardizedURL</key>
3553+
<string>http://test.com/unescaped%7Cpipe</string>
3554+
<key>user</key>
3555+
<string>&lt;null&gt;</string>
3556+
</dict>
3557+
</dict>
35043558
<dict>
35053559
<key>In-Title</key>
35063560
<string>NSURLWithString-parse-absolute-escape-007</string>

TestFoundation/TestURL.swift

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -248,25 +248,35 @@ class TestURL : XCTestCase {
248248
default:
249249
XCTFail()
250250
}
251-
if title == "NSURLWithString-parse-ambiguous-url-001" {
252-
// TODO: Fix this test
253-
} else {
254-
if let url = url {
255-
let results = generateResults(url, pathComponent: inPathComponent, pathExtension: inPathExtension)
256-
if let expected = expectedNSResult as? [String: Any] {
257-
let (isEqual, differences) = compareResults(url, expected: expected, got: results)
258-
XCTAssertTrue(isEqual, "\(title): \(differences.joined(separator: "\n"))")
259-
} else {
260-
XCTFail("\(url) should not be a valid url")
261-
}
251+
252+
#if os(Windows)
253+
// On Windows, pipes are valid charcters which can be used
254+
// to replace a ':'. See RFC 8089 Section E.2.2 for
255+
// details.
256+
let skippedPipeTest = "NSURLWithString-parse-absolute-escape-006"
257+
#else
258+
let skippedPipeTest = "NSURLWithString-parse-absolute-escape-006-Windows"
259+
#endif
260+
let skippedTests = [
261+
"NSURLWithString-parse-ambiguous-url-001", // TODO: Fix Test
262+
skippedPipeTest,
263+
]
264+
if skippedTests.contains(title) { continue }
265+
266+
if let url = url {
267+
let results = generateResults(url, pathComponent: inPathComponent, pathExtension: inPathExtension)
268+
if let expected = expectedNSResult as? [String: Any] {
269+
let (isEqual, differences) = compareResults(url, expected: expected, got: results)
270+
XCTAssertTrue(isEqual, "\(title): \(differences.joined(separator: "\n"))")
262271
} else {
263-
XCTAssertEqual(expectedNSResult as? String, kNullURLString)
272+
XCTFail("\(url) should not be a valid url")
264273
}
274+
} else {
275+
XCTAssertEqual(expectedNSResult as? String, kNullURLString)
265276
}
266277
}
267-
268278
}
269-
279+
270280
static let gBaseTemporaryDirectoryPath = (NSTemporaryDirectory() as NSString).appendingPathComponent("org.swift.foundation.TestFoundation.TestURL.\(ProcessInfo.processInfo.processIdentifier)")
271281
static var gBaseCurrentWorkingDirectoryPath : String {
272282
return FileManager.default.currentDirectoryPath

0 commit comments

Comments
 (0)