mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Fix issue with URL normalization, add tests
This commit is contained in:
parent
2e3ff15b51
commit
c86c18507e
2 changed files with 19 additions and 2 deletions
|
|
@ -26,9 +26,13 @@ public func normalizeURL(_ dirtyURL: String) -> String {
|
|||
}
|
||||
|
||||
urlObject.queryItems = urlObject.queryItems?.filter { item in
|
||||
item.name.starts(with: "utm_")
|
||||
!item.name.starts(with: "utm_")
|
||||
}
|
||||
|
||||
urlObject.queryItems = urlObject.queryItems?.sorted(by: { first, second in
|
||||
first.name <= second.name
|
||||
})
|
||||
|
||||
if /* options.removeTrailingSlash */ true {
|
||||
urlObject.path = urlObject.path.replacingRegex(pattern: "/$", replaceWith: "")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,20 @@ final class UtilsTests: XCTestCase {
|
|||
XCTAssertEqual("Hello", "Hello")
|
||||
}
|
||||
|
||||
func testNormalizeUrl() {
|
||||
// trailing slash removed
|
||||
XCTAssertEqual(normalizeURL("https://omnivore.app/"), "https://omnivore.app")
|
||||
|
||||
// utm_ removed
|
||||
XCTAssertEqual(normalizeURL("https://omnivore.app/?aa=a&bb=b&utm_track=track&cc=c"), "https://omnivore.app?aa=a&bb=b&cc=c")
|
||||
|
||||
// query params sorted
|
||||
XCTAssertEqual(normalizeURL("https://omnivore.app/?aa=a&cc=c&bb=b"), "https://omnivore.app?aa=a&bb=b&cc=c")
|
||||
XCTAssertEqual(normalizeURL("https://omnivore.app/?cc=c&bb=b&aa=a"), "https://omnivore.app?aa=a&bb=b&cc=c")
|
||||
}
|
||||
|
||||
static var allTests = [
|
||||
("testExample", testExample)
|
||||
("testExample", testExample),
|
||||
("testNormalizeUrl", testNormalizeUrl)
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue