Skip to content

Glob filter 1/2 also matches 1\2, and excluding -*/* also hides C:\temp: / and \ are masked to the same character #132

Description

@matt-edmondson

What's wrong

The #114 fix stops DotNet.Glob treating slashes as path separators. It does this by masking them in both the pattern and the text before matching (TextFilter/TextFilter.cs ~lines 405–415 at c4eec7b):

private const char MaskedPathSeparator = '\uE000';
private static string MaskPathSeparators(string value) =>
    value.Replace('/', MaskedPathSeparator).Replace('\\', MaskedPathSeparator);

Both / and \ map to the same private-use character, so after masking the glob can no longer tell them apart.

Reproduction (observed on net10.0)

TextFilter.Filter(["C:\\temp\\x", "1/2", "1\\2"], "1/2", TextFilterType.Glob);
// actual:   ["1/2", "1\\2"]      expected: ["1/2"]

TextFilter.IsMatch("a\\b", "a/b", TextFilterType.Glob, TextFilterMatchOptions.ByWholeString);
// actual:   true                 expected: false

TextFilter.Filter(["C:\\temp", "http://x", "plain"], "-*/*", TextFilterType.Glob);
// actual:   ["plain"]            expected: ["C:\\temp", "plain"]

Why it matters

The masking exists because "a slash is an ordinary character" in arbitrary text. The side effect is that the two slashes are now interchangeable. A user who excludes URLs with -*/* also loses every Windows path. Filtering for and/or or 1/2 also shows backslash variants. Regex and plain-text filtering don't do this, so the result depends on which filter type is selected.

Suggested fix / acceptance criteria

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions