Skip to content

Commit

Permalink
Merge pull request #3 from devxoul/normalize-query-fragment
Browse files Browse the repository at this point in the history
Remove query and fragment when normalizing URLs.
  • Loading branch information
devxoul committed Feb 23, 2016
2 parents f6fda7b + 0d6453f commit e23c50b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/URLNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public class URLNavigator {
guard dirtyURL.URLValue != nil else {
return dirtyURL
}
var URLString = dirtyURL.URLStringValue
var URLString = dirtyURL.URLStringValue.componentsSeparatedByString("?")[0].componentsSeparatedByString("#")[0]
URLString = self.replaceRegex(":/{3,}", "://", URLString)
URLString = self.replaceRegex("(?<!:)/{2,}", "/", URLString)
URLString = self.replaceRegex("/+$", "", URLString)
Expand Down
12 changes: 9 additions & 3 deletions Tests/URLNavigatorInternalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class URLNavigatorInternalTests: XCTestCase {
XCTAssertEqual(URLPattern, "myapp://user/<id>/<object>")
XCTAssertEqual(values as! [String: String], ["id": "1", "object": "posts"])
}();
{
let from = ["myapp://alert"]
let (URLPattern, values) = URLNavigator.matchURL("myapp://alert?title=hello&message=world", from: from)!
XCTAssertEqual(URLPattern, "myapp://alert")
XCTAssertEqual(values.count, 0)
}();
{
let from = ["http://<path:url>"]
let (URLPattern, values) = URLNavigator.matchURL("http://xoul.kr", from: from)!
Expand All @@ -75,20 +81,20 @@ class URLNavigatorInternalTests: XCTestCase {
let from = ["http://<path:url>"]
let (URLPattern, values) = URLNavigator.matchURL("http://google.com/search?q=URLNavigator", from: from)!
XCTAssertEqual(URLPattern, "http://<path:url>")
XCTAssertEqual(values as! [String: String], ["url": "google.com/search?q=URLNavigator"])
XCTAssertEqual(values as! [String: String], ["url": "google.com/search"])
}();
{
let from = ["http://<path:url>"]
let (URLPattern, values) = URLNavigator.matchURL("http://google.com/search/?q=URLNavigator", from: from)!
XCTAssertEqual(URLPattern, "http://<path:url>")
XCTAssertEqual(values as! [String: String], ["url": "google.com/search/?q=URLNavigator"])
XCTAssertEqual(values as! [String: String], ["url": "google.com/search"])
}();
}

func testNormalizedURL() {
XCTAssertEqual(URLNavigator.normalizedURL("myapp://user/<id>/hello").URLStringValue, "myapp://user/<id>/hello")
XCTAssertEqual(URLNavigator.normalizedURL("myapp:///////user///<id>//hello/??/#abc=/def").URLStringValue,
"myapp://user/<id>/hello/??/#abc=/def")
"myapp://user/<id>/hello")
XCTAssertEqual(URLNavigator.normalizedURL("https://<path:_>").URLStringValue, "https://<path:_>")
}

Expand Down

0 comments on commit e23c50b

Please sign in to comment.