Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #109 tests & fix #117

Merged
merged 2 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}
}