Skip to content

Branch patterns with POSIX character classes like [[:digit:]] silently match the wrong branches #56

Description

@matt-edmondson

What's wrong

BranchPattern says it honours the same constructs as git's wildmatch for git branch --list (GitBranchStateCache/Refs/BranchPattern.cs:22-25). The #43 fix added ranges, sets, negation and escapes, but not POSIX character classes: [:alpha:], [:digit:], [:alnum:], [:upper:], [:lower:], [:space:], [:xdigit:], [:punct:] and the rest. git supports all of these.

In TryMatchBracket (BranchPattern.cs:190-214), the first ] after [[:digit: closes the bracket. The expression becomes the set { '[', ':', 'd', 'i', 'g', 't' } and the second ] is matched as a literal character.

Failure scenario

  • Pattern: origin/release-[[:digit:]]*
  • Branch: origin/release-1.0
  • Here: no match, because 1 is not in the set.
  • git: git branch --list 'release-[[:digit:]]*' lists the branch.

TryParse accepts the pattern, so /state and /branches return 200 with those branches missing. The client never hears about assets changed on them. The same pattern also wrongly matches a branch such as origin/release-d]x.

Suggested fix / acceptance criteria

  • In TryMatchBracket, recognise [:name:] as a bracket member and test the character with the matching ASCII predicate (char.IsAsciiDigit, char.IsAsciiLetter, and so on). Keep the linear walk with no regular expressions.
  • Reject an unknown class name such as [[:bogus:]] in TryParse with a 400, rather than letting it mismatch silently. git's wildmatch aborts the match in that case.
  • Add tests for [[:digit:]], [[:digit:]], [[:alpha:]_-], a mix like [a[:digit:]], and the malformed [[:bogus:]].
  • Update the remarks at BranchPattern.cs:22-25 to list the classes.

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