urlPattern matching differences with and without query parameters (incorrect documentation?)

3,540 views
Skip to first unread message

Blake Norrish

unread,
Jul 21, 2016, 9:19:07 PM7/21/16
to wiremock-user

Configuring standalone Wiremock via json in /mappings, ran into the following behavior:

mapping: "urlPattern": "/your/url"
test:          /your/url
result: Match! (as expected)

mapping: "urlPattern": "/your/([a-z]*)"
test:          /your/url"
result: Match! (as expected)

mapping: "urlPattern": "/your/([a-z]*)?and=query"
test:          /your/url?and=query"
result: No Match... note this is the exact example used in the "Regex matching on path and query" section here: http://wiremock.org/docs/request-matching/

It seems that the addition of query parameters changes the way regex is applied to the PATH portion of the url.

To get the documentation example to work, you need to do the following:

mapping: "urlPattern": "\\/your\\/([a-z]*)\?and=query"
test:          /your/url?and=query
result: Match! (note the double backslash before every forward slash and the question mark)

It seems like the best approach would be to use urlPathPattern in addition to queryParameters, rather than regex on the combined URL.  However, the documentation seems to be incorrect ("Regex matching on path and query" here: http://wiremock.org/docs/request-matching/), unless I am missing something.




 


Blake Norrish

unread,
Jul 26, 2016, 2:29:50 PM7/26/16
to wiremock-user
The correct urlPattern should actually be:
"/your/([a-z]*)\\?and=query"

For java, the forward slash ('/') does not need to be escaped... but the question mark ('?') does.  Submitted PR to update doc.
https://github.com/tomakehurst/wiremock/pull/470
Reply all
Reply to author
Forward
0 new messages