Skip to content

Commit

Permalink
Merge pull request #117 from getfiit/issues-109_tests
Browse files Browse the repository at this point in the history
issue #109 tests & fix
  • Loading branch information
devxoul authored Mar 29, 2019
2 parents 52cd7a8 + 540c74d commit c7d9092
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/URLMatcher/URLMatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ open class URLMatcher {
return false
}
}
return hasSameNumberOfComponents || containsPathPlaceholderComponent
return hasSameNumberOfComponents || (containsPathPlaceholderComponent && stringPathComponents.count > candidatePathComponents.count)
}

func stringPathComponents(from url: URLConvertible) -> [String] {
Expand Down
20 changes: 20 additions & 0 deletions Tests/URLMatcherTests/URLMatcherSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,25 @@ final class URLMatcherSpec: QuickSpec {
expect(result?.pattern) == "https://<path:url>"
expect(result?.values["url"] as? String) == "google.com/search"
}

it("returns nil when there's no candidates (issues-109)") {
let candidates = ["/anything/<path:url>"]
let result = matcher.match("", from: candidates)
expect(result).to(beNil())
}

it("returns nil when there's no candidates (issues-109)") {
let candidates = ["http://host/anything/<path:url>"]
let result = matcher.match("http://host/anything", from: candidates)
expect(result).to(beNil())
}

it("returns same candidate (issues-109)") {
let candidates1 = ["http://host/anything/<path:url>", "http://host/anything"]
let result1 = matcher.match("http://host/anything", from: candidates1)
let candidates2 = ["http://host/anything", "http://host/anything/<path:url>"]
let result2 = matcher.match("http://host/anything", from: candidates2)
expect(result1?.pattern).to(equal(result2?.pattern))
}
}
}

0 comments on commit c7d9092

Please sign in to comment.