mockhttp icon indicating copy to clipboard operation
mockhttp copied to clipboard

QueryMatcher Case Sensitiviy

Open archerbird opened this issue 1 year ago • 3 comments

Would it be possible to add an option to make the QueryMatcher check for parameter keys in a case insensitive?

archerbird avatar Dec 13 '23 21:12 archerbird

I agree! not only for parameters but also for urls and json-strings would be nice

Iceeman76 avatar Jan 29 '24 14:01 Iceeman76

I wonder if a QueryStringMatcherOptions class was added. Something along the lines the following. The WithQueryString extension methods could take an optional QueryStringMatcherOptions and construct a new instance if null. the new instance defaults to Ordinal Case Sensitive comparison.

Is this something you would accept in a PR?

/// <summary>
/// Provides options on how to match query strings.
/// </summary>
public sealed class QueryStringMatcherOptions
{
    /// <summary>
    /// Constructs a new instance of QueryStringMatcherOptions using the default ordinal comparison on keys and values.
    /// </summary>
    public QueryStringMatcherOptions() : this(StringComparer.Ordinal, StringComparer.Ordinal)
    {
    }

    /// <summary>
    /// Constructs a new instance of QueryStringMatcherOptions using the default ordinal comparison on keys and values.
    /// </summary>
    public QueryStringMatcherOptions(IEqualityComparer<string>? key = null, IEqualityComparer<string>? value = null)
    {
        KeyComparer = key ?? StringComparer.Ordinal;
        ValueComparer = value ?? StringComparer.Ordinal;
    }

    /// <summary>
    /// The comparer to use for keys
    /// </summary>
    public IEqualityComparer<string> KeyComparer { get; }

    /// <summary>
    /// The comparer to use for values
    /// </summary>
    public IEqualityComparer<string> ValueComparer { get; }
}

pbolduc avatar Feb 17 '24 18:02 pbolduc

Would it be possible to add an option to make the QueryMatcher check for parameter keys in a case insensitive?

Could you explain your use case on the problem you are trying to solve by performing a case insensitive comparison? Knowing the problem you are trying to solve will ensure any features developed will match the problem you are trying to solve.

pbolduc avatar Feb 18 '24 02:02 pbolduc