Skip to content

Match POSIX character classes in branch patterns [patch] - #95

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/56-posix-character-classes
Oct 20, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/56-posix-character-classes

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #56

Summary

BranchPattern read [[:digit:]] as the plain set { '[', ':', 'd', 'i', 'g', 't' } closed by the first ], so origin/release-[[:digit:]]* left out origin/release-1.0 and matched origin/release-d]x. Bracket expressions now honour the POSIX classes git's wildmatch knows.

  • TryReadClass recognises [:name:] inside a bracket the way wildmatch does: after [:, the first ] ends a class only when a : comes straight before it; otherwise the [ is an ordinary member.
  • IsInClass tests the character against the ASCII range for alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper and xdigit. The walk stays linear, with no regular expressions.
  • TryParse refuses a pattern that names an unknown class ([[:bogus:]]), so the endpoints answer 400 instead of silently matching nothing. git abandons the match in that case.
  • The class remarks list the supported classes.

Testing

  • New BranchPatternTests: [[:digit:]], [[:alnum:]], [[:alpha:]_-], [a[:digit:]], a negated class, [[:x] as an ordinary set, [[:bogus:]] refused, and an escaped look-alike accepted.
  • With the BranchPattern.cs change reverted, 5 of the new tests fail (digit, alnum, mixed, negated, unknown class). With it, they pass.
  • Full GitBranchStateCache.Tests suite: 261/261 pass.

Generated by Claude Code

A pattern such as release-[[:digit:]]* was read as a plain set closed by
the first ], so it left out release-1.0 and matched release-d]x instead.
Bracket expressions now honour the twelve classes git's wildmatch knows,
alone or mixed with other members, and a pattern naming an unknown class
such as [:bogus:] is refused, since git abandons the match for it.

Fixes #56

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LxJek7fRQ3W1PmY5cm9btG
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 4656d1c into main Oct 20, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/56-posix-character-classes branch October 20, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants