-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GuidWildcardMatcher to match on GUIDs #685
Comments
It would also be an option to update the wildcard matcher. Just thinking.... |
True, I mean could it be a more general matcher available in JSON as well? I forked and trying to play with it to see. |
OK, after playing I see what you mean by updating the wildcard matcher, since it extends return patterns.Select(pattern => new AnyOf<string, StringPattern>(
new StringPattern
{
Pattern = "^" + Regex.Escape(pattern.GetPattern())
.Replace(@"\{GUIDD}", "([A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12})")
.Replace(@"\{GUIDN}", "([A-Z0-9]{32})")
.Replace(@"\{GUIDP}", @"(\([A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}\))")
.Replace(@"\*",".*")
.Replace(@"\?", ".")
+ "$",
PatternAsFile = pattern.IsSecond ? pattern.Second.PatternAsFile : null
}))
.ToArray(); and was able to get things working. My only thought about putting it in the Anyways, thanks for the consideration. |
What we also could do is 'extending' the RegEx specification by adding GUID, GUIDN or GUIDP. So like So maybe new logic should be moved to a separate helper NuGet / project / class and then replace all logic in WireMock.Net which uses Regex, by this new "RegexExtended". ? |
I like the idea. I took a look at the RegexParser. ScanBackslash method and it is quite involved and isn't really built for extensibility, which would result in divergent code paths. So doesn't feel like a longterm solution? Unless could be added to the main library. Anyways, if it were to be done maybe something similar to the |
I just meant that we don't need to write parser code, just use your replace logic, like: void Main()
{
var pattern = @"\d \GUID";
var r = new Regex2(pattern, RegexOptions.Compiled);
r.Matches("1 baf04077-a3c0-454b-ac6f-9fec00b8e170").Dump();
}
public class Regex2 : Regex
{
public Regex2(string pattern, RegexOptions options) : base(Replace(pattern), options)
{
}
private static string Replace(string pattern)
{
return pattern.Replace(@"\GUID", @"[0-9A-Fa-f\-]{36}");
}
} |
I see what you mean. |
OK, I got a library where I have most of the work done. Will try to package into a nuget later and publish. |
Cool. However, if it's only a single class file, maybe it's better to just include it in this project first. |
Meh... it could be useful for others too I suppose. |
I could try to integrate it on my fork as a single class integrated and put up a PR. Would that be helpful? |
Hello @brogdogg; Did you achieve any progress on this? |
@StefH I had it done and then realized my line endings got jacked... and then Thanksgiving happened, so took a break. Will try to figure out my line endings and get it ready. |
Thanks @StefH , I was able to pull the latest version and use this feature. Thanks again for being so open to my feature suggestion. |
Is your feature request related to a problem? Please describe.
I have been using the
RegexMatcher
to do matches for paths with GUIDs, but after a while thePattern
in the JSON mappings becomes unwieldly long in length when a few GUIDs are used.Describe the solution you'd like
Would like a matcher to allow for matching a GUID (mostly in the
Path
). For example:Path
-http://localhost/v1.0/4a7eaad5-bbe7-4579-bb0b-7c85352fe1b6/task/edef5b4a-33bb-4920-bb42-1d5e6283984e
JSON mapping:
Where the tokens used in the pattern match up with the
GUID.ToString(string? format)
method as described here.Describe alternatives you've considered
None - I can use the
RegexMatcher
if the feature is not accepted.Is your feature request supported by WireMock (java version)? Please provide details.
I do not believe this is supported in the java version (I did a search and couldn't find anything that I could see)
The text was updated successfully, but these errors were encountered: