File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
main/kotlin/com/github/mduesterhoeft/router
test/kotlin/com/github/mduesterhoeft/router Expand file tree Collapse file tree 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) {
1717 }
1818
1919 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())
2222
2323 fun String.trimSlashes () = " ^(/)?(.*?)(/)?$" .toRegex().replace(this ) { result -> result.groupValues[2 ] }
2424 }
Original file line number Diff line number Diff line change @@ -34,4 +34,16 @@ class UriTemplateTest {
3434 .isEqualTo(mapOf (" first" to " first-value" , " second" to " second-value" ))
3535 then(UriTemplate .from(" /some" ).extract(" /some" )).isEmpty()
3636 }
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+ }
3749}
You can’t perform that action at this time.
0 commit comments