Wrong mapping is matched with different value for same url param #217

Closed
opened 2025-12-29 14:25:27 +01:00 by adam · 3 comments
Owner

Originally created by @gregoks on GitHub (Oct 10, 2019).

Hi again! :)

Can you please check if its a bug for case when I have 2 mappings with the same url param but with different values:

first mapping:

{
    "Guid": "e6a48f48-591a-48ff-ae6d-b42fd38321b9",
    "Priority": 1,
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "*/test",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ],
      "Params": [
        {
          "Name": "abc",
          "Matchers": [
            {
              "Name": "RegexMatcher",
              "Pattern": "[ar]",
              "IgnoreCase": true
            }
          ]
        }
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyDestination": "SameAsSource",
      "Body": "hello ar"
    }
  }

second mapping:

{
   "Guid": "7e45210f-fc44-4cf6-9f16-50c17a4611f2",
   "Priority": 1,
   "Request": {
     "Path": {
       "Matchers": [
         {
           "Name": "WildcardMatcher",
           "Pattern": "*/test",
           "IgnoreCase": false
         }
       ]
     },
     "Methods": [
       "GET"
     ],
     "Params": [
       {
         "Name": "abc",
         "Matchers": [
           {
             "Name": "RegexMatcher",
             "Pattern": "[ru]",
             "IgnoreCase": true
           }
         ]
       }
     ]
   },
   "Response": {
     "StatusCode": 200,
     "BodyDestination": "SameAsSource",
     "Body": "hello ru"
   }
 }

For these 2 API calls:

http://localhost:5566/test?abc=ru
http://localhost:5566/test?abc=ar

I get the same following response:

hello ar

Obviously I expect to get "hello ru" for the first one.
I have also noticed that if you change the values of the param to numbers it works correctly for some reason :|

These are my requests:

[
  {
    "Guid": "2619e322-3ff1-4f89-9983-18c844a8081b",
    "Request": {
      "ClientIP": "127.0.0.1",
      "DateTime": "2019-10-10T17:13:44.5390958Z",
      "Path": "/test",
      "AbsolutePath": "/test",
      "Url": "http://localhost:5566/test?abc=ar",
      "AbsoluteUrl": "http://localhost:5566/test?abc=ar",
      "Query": {
        "abc": [
          "ar"
        ]
      },
      "Method": "GET",
      "Headers": {
        "Connection": [
          "keep-alive"
        ],
        "Accept": [
          "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
        ],
        "Accept-Encoding": [
          "gzip, deflate, br"
        ],
        "Accept-Language": [
          "en-US,en;q=0.9,he;q=0.8"
        ],
        "Cookie": [
          "MUIDB=3D48D196A6666135126EDCE1A71760EF"
        ],
        "Host": [
          "localhost:5566"
        ],
        "User-Agent": [
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
        ],
        "Upgrade-Insecure-Requests": [
          "1"
        ],
        "Sec-Fetch-Mode": [
          "navigate"
        ],
        "Sec-Fetch-User": [
          "?1"
        ],
        "Sec-Fetch-Site": [
          "none"
        ]
      },
      "Cookies": {
        "MUIDB": "3D48D196A6666135126EDCE1A71760EF"
      }
    },
    "Response": {
      "StatusCode": 200,
      "Headers": {},
      "BodyDestination": "SameAsSource",
      "Body": "hello ar",
      "BodyEncoding": {
        "CodePage": 65001,
        "EncodingName": "Unicode (UTF-8)",
        "WebName": "utf-8"
      },
      "DetectedBodyType": 1,
      "DetectedBodyTypeFromContentType": 0
    },
    "MappingGuid": "e6a48f48-591a-48ff-ae6d-b42fd38321b9",
    "RequestMatchResult": {
      "TotalScore": 3.0,
      "TotalNumber": 3,
      "IsPerfectMatch": true,
      "AverageTotalScore": 1.0,
      "MatchDetails": [
        {
          "Name": "PathMatcher",
          "Score": 1.0
        },
        {
          "Name": "MethodMatcher",
          "Score": 1.0
        },
        {
          "Name": "ParamMatcher",
          "Score": 1.0
        }
      ]
    }
  },
  {
    "Guid": "733068ed-1218-4f29-ae3a-b42945bc53d6",
    "Request": {
      "ClientIP": "127.0.0.1",
      "DateTime": "2019-10-10T17:13:49.0420736Z",
      "Path": "/test",
      "AbsolutePath": "/test",
      "Url": "http://localhost:5566/test?abc=ru",
      "AbsoluteUrl": "http://localhost:5566/test?abc=ru",
      "Query": {
        "abc": [
          "ru"
        ]
      },
      "Method": "GET",
      "Headers": {
        "Connection": [
          "keep-alive"
        ],
        "Accept": [
          "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
        ],
        "Accept-Encoding": [
          "gzip, deflate, br"
        ],
        "Accept-Language": [
          "en-US,en;q=0.9,he;q=0.8"
        ],
        "Cookie": [
          "MUIDB=3D48D196A6666135126EDCE1A71760EF"
        ],
        "Host": [
          "localhost:5566"
        ],
        "User-Agent": [
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
        ],
        "Upgrade-Insecure-Requests": [
          "1"
        ],
        "Sec-Fetch-Mode": [
          "navigate"
        ],
        "Sec-Fetch-User": [
          "?1"
        ],
        "Sec-Fetch-Site": [
          "none"
        ]
      },
      "Cookies": {
        "MUIDB": "3D48D196A6666135126EDCE1A71760EF"
      }
    },
    "Response": {
      "StatusCode": 200,
      "Headers": {},
      "BodyDestination": "SameAsSource",
      "Body": "hello ar",
      "BodyEncoding": {
        "CodePage": 65001,
        "EncodingName": "Unicode (UTF-8)",
        "WebName": "utf-8"
      },
      "DetectedBodyType": 1,
      "DetectedBodyTypeFromContentType": 0
    },
    "MappingGuid": "e6a48f48-591a-48ff-ae6d-b42fd38321b9",
    "RequestMatchResult": {
      "TotalScore": 3.0,
      "TotalNumber": 3,
      "IsPerfectMatch": true,
      "AverageTotalScore": 1.0,
      "MatchDetails": [
        {
          "Name": "PathMatcher",
          "Score": 1.0
        },
        {
          "Name": "MethodMatcher",
          "Score": 1.0
        },
        {
          "Name": "ParamMatcher",
          "Score": 1.0
        }
      ]
    }
  }
]
Originally created by @gregoks on GitHub (Oct 10, 2019). Hi again! :) Can you please check if its a bug for case when I have 2 mappings with the same url param but with different values: first mapping: ``` js { "Guid": "e6a48f48-591a-48ff-ae6d-b42fd38321b9", "Priority": 1, "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "*/test", "IgnoreCase": false } ] }, "Methods": [ "GET" ], "Params": [ { "Name": "abc", "Matchers": [ { "Name": "RegexMatcher", "Pattern": "[ar]", "IgnoreCase": true } ] } ] }, "Response": { "StatusCode": 200, "BodyDestination": "SameAsSource", "Body": "hello ar" } } ``` second mapping: ``` js { "Guid": "7e45210f-fc44-4cf6-9f16-50c17a4611f2", "Priority": 1, "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "*/test", "IgnoreCase": false } ] }, "Methods": [ "GET" ], "Params": [ { "Name": "abc", "Matchers": [ { "Name": "RegexMatcher", "Pattern": "[ru]", "IgnoreCase": true } ] } ] }, "Response": { "StatusCode": 200, "BodyDestination": "SameAsSource", "Body": "hello ru" } } ``` For these 2 API calls: ``` http://localhost:5566/test?abc=ru http://localhost:5566/test?abc=ar ``` I get the same following response: hello ar Obviously I expect to get "hello ru" for the first one. I have also noticed that if you change the values of the param to numbers it works correctly for some reason :| These are my requests: ``` js [ { "Guid": "2619e322-3ff1-4f89-9983-18c844a8081b", "Request": { "ClientIP": "127.0.0.1", "DateTime": "2019-10-10T17:13:44.5390958Z", "Path": "/test", "AbsolutePath": "/test", "Url": "http://localhost:5566/test?abc=ar", "AbsoluteUrl": "http://localhost:5566/test?abc=ar", "Query": { "abc": [ "ar" ] }, "Method": "GET", "Headers": { "Connection": [ "keep-alive" ], "Accept": [ "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" ], "Accept-Encoding": [ "gzip, deflate, br" ], "Accept-Language": [ "en-US,en;q=0.9,he;q=0.8" ], "Cookie": [ "MUIDB=3D48D196A6666135126EDCE1A71760EF" ], "Host": [ "localhost:5566" ], "User-Agent": [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36" ], "Upgrade-Insecure-Requests": [ "1" ], "Sec-Fetch-Mode": [ "navigate" ], "Sec-Fetch-User": [ "?1" ], "Sec-Fetch-Site": [ "none" ] }, "Cookies": { "MUIDB": "3D48D196A6666135126EDCE1A71760EF" } }, "Response": { "StatusCode": 200, "Headers": {}, "BodyDestination": "SameAsSource", "Body": "hello ar", "BodyEncoding": { "CodePage": 65001, "EncodingName": "Unicode (UTF-8)", "WebName": "utf-8" }, "DetectedBodyType": 1, "DetectedBodyTypeFromContentType": 0 }, "MappingGuid": "e6a48f48-591a-48ff-ae6d-b42fd38321b9", "RequestMatchResult": { "TotalScore": 3.0, "TotalNumber": 3, "IsPerfectMatch": true, "AverageTotalScore": 1.0, "MatchDetails": [ { "Name": "PathMatcher", "Score": 1.0 }, { "Name": "MethodMatcher", "Score": 1.0 }, { "Name": "ParamMatcher", "Score": 1.0 } ] } }, { "Guid": "733068ed-1218-4f29-ae3a-b42945bc53d6", "Request": { "ClientIP": "127.0.0.1", "DateTime": "2019-10-10T17:13:49.0420736Z", "Path": "/test", "AbsolutePath": "/test", "Url": "http://localhost:5566/test?abc=ru", "AbsoluteUrl": "http://localhost:5566/test?abc=ru", "Query": { "abc": [ "ru" ] }, "Method": "GET", "Headers": { "Connection": [ "keep-alive" ], "Accept": [ "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" ], "Accept-Encoding": [ "gzip, deflate, br" ], "Accept-Language": [ "en-US,en;q=0.9,he;q=0.8" ], "Cookie": [ "MUIDB=3D48D196A6666135126EDCE1A71760EF" ], "Host": [ "localhost:5566" ], "User-Agent": [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36" ], "Upgrade-Insecure-Requests": [ "1" ], "Sec-Fetch-Mode": [ "navigate" ], "Sec-Fetch-User": [ "?1" ], "Sec-Fetch-Site": [ "none" ] }, "Cookies": { "MUIDB": "3D48D196A6666135126EDCE1A71760EF" } }, "Response": { "StatusCode": 200, "Headers": {}, "BodyDestination": "SameAsSource", "Body": "hello ar", "BodyEncoding": { "CodePage": 65001, "EncodingName": "Unicode (UTF-8)", "WebName": "utf-8" }, "DetectedBodyType": 1, "DetectedBodyTypeFromContentType": 0 }, "MappingGuid": "e6a48f48-591a-48ff-ae6d-b42fd38321b9", "RequestMatchResult": { "TotalScore": 3.0, "TotalNumber": 3, "IsPerfectMatch": true, "AverageTotalScore": 1.0, "MatchDetails": [ { "Name": "PathMatcher", "Score": 1.0 }, { "Name": "MethodMatcher", "Score": 1.0 }, { "Name": "ParamMatcher", "Score": 1.0 } ] } } ] ```
adam added the question label 2025-12-29 14:25:27 +01:00
adam closed this issue 2025-12-29 14:25:27 +01:00
Author
Owner

@StefH commented on GitHub (Oct 10, 2019):

A regex like [ar] will match any the character a and r.

If you need exact match you need:
^ar$
and
^ru$

@StefH commented on GitHub (Oct 10, 2019): A regex like [ar] will match any the character `a` and `r`. If you need exact match you need: `^ar$` and `^ru$`
Author
Owner

@gregoks commented on GitHub (Oct 15, 2019):

my bad! Thanks @StefH

@gregoks commented on GitHub (Oct 15, 2019): my bad! Thanks @StefH
Author
Owner

@StefH commented on GitHub (Oct 15, 2019):

closing

@StefH commented on GitHub (Oct 15, 2019): closing
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#217