Skip to content

Commit

Permalink
Merge pull request #22 from hyperoslo/feature/url-with-no-slash
Browse files Browse the repository at this point in the history
Feature: URL with no slash
  • Loading branch information
zenangst committed Dec 22, 2015
2 parents 905003b + e2759d7 commit f41b341
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Source/Compass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct Compass {
var result = false
let query = url.absoluteString.substringFromIndex(scheme.endIndex)

guard !(query.containsString("/?") || query.containsString("/#"))
guard !(query.containsString("?") || query.containsString("#"))
else { return parseAsURL(url, completion: completion) }

for route in routes.sort({ $0 < $1 }) {
Expand Down
19 changes: 18 additions & 1 deletion Tests/TestCompass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,26 @@ class TestCompass: XCTestCase {
self.waitForExpectationsWithTimeout(4.0, handler:nil)
}

func testParseRegularURLWithSlashQuery() {
let expectation = self.expectationWithDescription("Parse URL with slash query")
let url = NSURL(string: "compassTests://callback/?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")!

Compass.parse(url) { route, arguments in
XCTAssertEqual(route, "callback")
XCTAssertEqual(arguments.count, 3)
XCTAssertEqual(arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l")
XCTAssertEqual(arguments["expires_in"], "3600")
XCTAssertEqual(arguments["token_type"], "Bearer")

expectation.fulfill()
}

self.waitForExpectationsWithTimeout(4.0, handler:nil)
}

func testParseRegularURLWithQuery() {
let expectation = self.expectationWithDescription("Parse URL with query")
let url = NSURL(string: "compassTests://callback/?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")!
let url = NSURL(string: "compassTests://callback?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")!

Compass.parse(url) { route, arguments in
XCTAssertEqual(route, "callback")
Expand Down

0 comments on commit f41b341

Please sign in to comment.