How can I correctly find or ignore the ? character from a request url in the RegexMatcher used via postman, not coded. #466

Closed
opened 2025-12-29 08:28:37 +01:00 by adam · 5 comments
Owner

Originally created by @lszlszl on GitHub (Nov 17, 2022).

Originally assigned to: @StefH on GitHub.

Latest stable wiremock version was downloaded and configured. I send messages to them via postman.

I configured a RegexMatcher, what is okay, if I do not send a ? in the url.

steps

  1. define RegexMatcher
    "Pattern": "(\/some\/service\/v1\/name)([?]{1})(param.source=SYSTEM){1}([&]{1})(param.id=123457890){1}$"
  2. do POST or PUT and configure a request / response via postman.
  3. check it with GET "__admin/mappings"
  4. send GET request to wiremock via postman.
    https://localhost/wiremock/some/service/v1/name?param.source=SYSTEM&param.id=123457890
  5. check response message

expected result:
answer arrives correctly with defined response message

actual result:
exception : "ClassName":"System.NullReferenceException","Message":"Object reference not set to an instance of an object.\

Please be specific so we can provide the best answer possible:
if I not use ? in the link and change it to other character (e.g. "a-z" "0-9" + & $ ), then the same expression will work correctly

I tried ([?]{1}), ([\?]{1}) (.*{1}) ((/u003F){1})
How can I define the part from de regexp correctly ([?]{1}) to find or ignore ?

Originally created by @lszlszl on GitHub (Nov 17, 2022). Originally assigned to: @StefH on GitHub. Latest stable wiremock version was downloaded and configured. I send messages to them via postman. I configured a RegexMatcher, what is okay, if I do not send a ? in the url. **steps** 1. define RegexMatcher `"Pattern": "(\/some\/service\/v1\/name)([?]{1})(param.source=SYSTEM){1}([&]{1})(param.id=123457890){1}$"` 2. do POST or PUT and configure a request / response via postman. 3. check it with GET "__admin/mappings" 4. send GET request to wiremock via postman. https://localhost/wiremock/some/service/v1/name?param.source=SYSTEM&param.id=123457890 5. check response message **expected result:** answer arrives correctly with defined response message **actual result:** exception : \"ClassName\":\"System.NullReferenceException\",\"Message\":\"Object reference not set to an instance of an object.\ Please be specific so we can provide the best answer possible: if I not use ? in the link and change it to other character (e.g. "a-z" "0-9" + & $ ), then the same expression will work correctly I tried ([?]{1}), ([\\?]{1}) (.*{1}) ((/u003F){1}) How can I define the part from de regexp correctly ([?]{1}) to find or ignore ?
adam added the question label 2025-12-29 08:28:37 +01:00
adam closed this issue 2025-12-29 08:28:37 +01:00
Author
Owner

@StefH commented on GitHub (Nov 17, 2022):

@lszlszl
Please provide the mappping json you send to wiremock.

@StefH commented on GitHub (Nov 17, 2022): @lszlszl Please provide the mappping json you send to wiremock.
Author
Owner

@lszlszl commented on GitHub (Nov 17, 2022):

{
	"Request": {
		"Path": {
			"Matchers": [
				{
					"Name": "RegexMatcher",
					"Pattern": "(\/some\/service\/v3\/name)([?]{1})(param.source=SYSTEM){1}([&]{1})(param.id=123457890){1}$"
				}
			]
		},
		"Methods": [
			"get"
		]
	},
	"Response": {
		"StatusCode": 200,
		"Body": "{\"msg\": \"Hello my world!\"}",
		"Headers": {
			"Content-Type": "application/json; charset=utf-8"
		}
	}
}
@lszlszl commented on GitHub (Nov 17, 2022): ``` json { "Request": { "Path": { "Matchers": [ { "Name": "RegexMatcher", "Pattern": "(\/some\/service\/v3\/name)([?]{1})(param.source=SYSTEM){1}([&]{1})(param.id=123457890){1}$" } ] }, "Methods": [ "get" ] }, "Response": { "StatusCode": 200, "Body": "{\"msg\": \"Hello my world!\"}", "Headers": { "Content-Type": "application/json; charset=utf-8" } } } ```
Author
Owner

@StefH commented on GitHub (Nov 18, 2022):

What I would suggest is:

1️⃣
Use a RegexMatcher for only the path : (\/some\/service\/v1\/name)

2️⃣
Use a RegexMatcher/ExactMatcher or WildcardMatcher for the Query Parameters:

"Params": [
        {
          "Name": "param.source",
          "Matchers": [
            {
              "Name": "ExactMatcher",
              "Pattern": "SYSTEM"
            }
          ]
        }
      ]
@StefH commented on GitHub (Nov 18, 2022): What I would suggest is: :one: Use a RegexMatcher for only the **path** : `(\/some\/service\/v1\/name)` :two: Use a RegexMatcher/ExactMatcher or WildcardMatcher for the Query Parameters: ``` json "Params": [ { "Name": "param.source", "Matchers": [ { "Name": "ExactMatcher", "Pattern": "SYSTEM" } ] } ] ```
Author
Owner

@lszlszl commented on GitHub (Nov 19, 2022):

{
     "Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "ExactMatcher",
                    "Pattern": "/some/service/v3/name",
                    "IgnoreCase": false
                }
            ]
        },
        "Params": [
            {
                "Name": "param.source",
                "Matchers": [
                    {
                        "Name": "ExactMatcher",
                        "Pattern": "SYSTEM"
                    }
                ]
            },
            {
                "Name": "param.id",
                "Matchers": [
                    {
                        "Name": "ExactMatcher",
                        "Pattern": "123457890"
                    }
                ]
            }
        ],
        "Methods": [
            "get"
        ]
    },
    "Response": {
        "StatusCode": "200",
        "Body": "{\"msg\":\"Hello my world!\"}",
        "Headers": {
            "Content-Type": "application/json;charset=utf-8"
        }
    }
}
@lszlszl commented on GitHub (Nov 19, 2022): ``` json { "Request": { "Path": { "Matchers": [ { "Name": "ExactMatcher", "Pattern": "/some/service/v3/name", "IgnoreCase": false } ] }, "Params": [ { "Name": "param.source", "Matchers": [ { "Name": "ExactMatcher", "Pattern": "SYSTEM" } ] }, { "Name": "param.id", "Matchers": [ { "Name": "ExactMatcher", "Pattern": "123457890" } ] } ], "Methods": [ "get" ] }, "Response": { "StatusCode": "200", "Body": "{\"msg\":\"Hello my world!\"}", "Headers": { "Content-Type": "application/json;charset=utf-8" } } } ```
Author
Owner

@lszlszl commented on GitHub (Nov 19, 2022):

okay, thank you! That"s working fine.

@lszlszl commented on GitHub (Nov 19, 2022): okay, thank you! That"s working fine.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#466