File tree 2 files changed +14
-2
lines changed
main/kotlin/com/github/mduesterhoeft/router
test/kotlin/com/github/mduesterhoeft/router
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ class UriTemplate private constructor(private val template: String) {
17
17
}
18
18
19
19
companion object {
20
- private val URI_TEMPLATE_FORMAT = " \\ {([^}]+?)(?::([^}]+))?\\ }" .toRegex()
21
- fun from (template : String ) = UriTemplate (template.trimSlashes())
20
+ private val URI_TEMPLATE_FORMAT = " \\ {([^}]+?)(?::([^}]+))?}" .toRegex()
21
+ fun from (template : String ) = UriTemplate (template.split( ' ? ' )[ 0 ]. trimSlashes())
22
22
23
23
fun String.trimSlashes () = " ^(/)?(.*?)(/)?$" .toRegex().replace(this ) { result -> result.groupValues[2 ] }
24
24
}
Original file line number Diff line number Diff line change @@ -34,4 +34,16 @@ class UriTemplateTest {
34
34
.isEqualTo(mapOf (" first" to " first-value" , " second" to " second-value" ))
35
35
then(UriTemplate .from(" /some" ).extract(" /some" )).isEmpty()
36
36
}
37
+
38
+ @Test
39
+ fun `should match with query parameter` () {
40
+ then(UriTemplate .from(" /some?a=1" ).matches(" /some" )).isTrue()
41
+ then(UriTemplate .from(" /some?a=1&b=2" ).matches(" /some" )).isTrue()
42
+ }
43
+
44
+ @Test
45
+ fun `should match with path parameter and query parameter` () {
46
+ then(UriTemplate .from(" /some/{id}?a=1" ).matches(" /some/${UUID .randomUUID()} " )).isTrue()
47
+ then(UriTemplate .from(" /some/{id}/other?a=1&b=2" ).matches(" /some/${UUID .randomUUID()} /other" )).isTrue()
48
+ }
37
49
}
You can’t perform that action at this time.
0 commit comments