2

I have a urlPattern:

"urlPattern" : "^\/blah\/players\/1000\/game\/tickets\\?drawFrom=(.*)&drawTo=(.*)&take=10&skip=0"

But when trying to match them, I get "Request not matched" and this error

<<<<< null. When using a regex, "?" should be "\\?". URLs must start with a /

The url regex is also showing up in the terminal as

^\/blah\/players\/1000\/game\/tickets\?drawFrom=(.*)&drawTo=(.*)&take=10&skip=0

I have used \\? instead of \? so I'm stuck on what the problem could be. I've also used almost identical regex in other places that's working fine.

EDIT: This is what the actual request looks like

/blah/players/1000/game/tickets?drawFrom=2018-01-01&drawTo=2018-02-02&take=10&skip=0
JoeGeC
  • 187
  • 3
  • 10
  • Can you post the request as well? And if there is a closest match output in terminal? Queries can be confusing with regexes, so without seeing what you're requesting, it might be difficult to see why the match is missing. – agoff May 21 '20 at 17:53
  • 1
    Sorry for the late reply. This is what the request looks like. /blah/players/1000/game/tickets?drawFrom=2018-01-01&drawTo=2018-02-02&take=10&skip=0 – JoeGeC May 26 '20 at 15:29
  • 1
    Hmm... Two things: 1. Try setting the url to start with... "/blah/...". I don't think you need to escape the `/` or start the string with a `^`. I think this is the actual relevant part of the error you're getting. 2. If that doesn't work, try matching on the url and query separately. You can use urlPath/urlPathPattern to check the url, and then a separate "queryParameters": { "drawFrom": { "matches": ".*" } } (sorry for poor formatting) – agoff May 26 '20 at 18:24
  • 1
    Ah, starting it without the escape and the ^ worked. Thank you. You can post it as an answer and I'll flag it as the accepted answer if you'd like :) – JoeGeC May 27 '20 at 16:26

1 Answers1

2

Your error is because the URL does not need the preceding ^ because WireMock knows that the URL begins with a /. Additionally, you do not need to escape the / characters.

This should work:

"urlPattern" : "/blah/players/1000/game/tickets\\?drawFrom=(.*)&drawTo=(.*)&take=10&skip=0"
agoff
  • 5,818
  • 1
  • 7
  • 20