Skip to content

Commit 0934205

Browse files
author
Chris Emerson
committed
Ensure matches? also matches templates with no template vars if the template is exactly the same as the uri
Authors: @chris-emerson @callwait
1 parent 8769861 commit 0934205

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/uritemplate_clj/match.clj

+2-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@
9494

9595
(defn matches? [^String template ^String uri]
9696
"Indicates if a given URI has at least one match against a URI template"
97-
(if (empty? (match-variables template uri))
98-
false
99-
true))
97+
(or (not (empty? (match-variables template uri)))
98+
(= template uri)))
10099

101100
(defn fill-with-nulls [^String template]
102101
"Create a version of the template with all variables set to ASCII

test/uritemplate_clj/match_test.clj

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@
6969
(is (not (matches? template uri2)))
7070
(is (not (matches? template uri3)))))
7171

72+
(deftest matches?-with-no-template-vars-test
73+
(let
74+
[template "http://www.example.org/no-template-vars"
75+
uri1 "http://www.example.org/no-template-vars"
76+
uri2 "http://www.example.org/other"]
77+
(is (matches? template uri1))
78+
(is (not (matches? template uri2)))))
79+
7280
(deftest fill-with-nulls-test
7381
(let
7482
[template "http://www.example.org/bla/{var}/{hello}"

0 commit comments

Comments
 (0)