Skip to content

fix brace alternation scanning with character classes - #115

Merged
bmatcuk merged 1 commit into
bmatcuk:masterfrom
sidsri14:master
Sep 19, 2026
Merged

bmatcuk merged 1 commit into
bmatcuk:masterfrom
sidsri14:master

Conversation

@sidsri14

Copy link
Copy Markdown
Contributor

Summary

Fixes #113. A character class inside a brace alternation (e.g. {[}],a} or {[a,b]x.md,real/path.txt}) was not skipped when the matcher scanned for the next alternative or the matching closing brace, so commas and braces contained in the class were treated as alternation syntax. As a result, ValidatePattern blessed patterns that Match could never match.

Root cause

Two helper scanners didn't account for character classes:

  • indexNextAlt (utils.go) — found the comma splitting alternatives; a comma inside a class was misread as a separator.
  • indexMatchedClosingAlt (match.go) — found the matching }; a } inside a class was misread as the closing brace.

The validator (doValidatePattern) already skips character classes correctly, which is why it approved these patterns while the matcher rejected them.

Change

Skip [...] character classes (including escaped bytes inside them) in both scanners, mirroring what the validator already does. This applies only when the pattern uses / as the separator; on systems where \ is the separator, escaping is disabled and classes are skipped at face value.

Tests

Added regression rows to matchTests covering both a comma and a closing-brace inside a character class within a brace alternation:

  • {[a,b]x.md,real/path.txt} matches ax.md, bx.md, real/path.txt, but not cx.md
  • {[}],a} matches }, a, but not b

Verified the rows fail on unpatched upstream (TestMatch reported "syntax error in pattern" for these patterns) and pass with this change. Full suite: go test -count=1 ./... → ok, go vet clean.

Notes

  • No behavior change for patterns without character classes inside alternations.
  • No CHANGELOG file exists in this repo; commit follows existing short-imperative style.

Assistance disclosure: this change was developed with the help of an AI coding assistant (Claude Code by Anthropic).

Character classes within a brace alternation (such as {[}],a}) were not
skipped when scanning for the next alternative or the matching closing
brace, so commas and braces inside the class were treated as alternation
syntax. ValidatePattern blessed these patterns, but Match could never
match them. Skip character classes in indexNextAlt and
indexMatchedClosingAlt, matching what the validator already does.
@sidsri14
sidsri14 marked this pull request as draft August 27, 2026 10:26
@bmatcuk
bmatcuk merged commit bf0b1d6 into bmatcuk:master Sep 19, 2026
@bmatcuk

bmatcuk commented Sep 19, 2026

Copy link
Copy Markdown
Owner

Looks like a good fix to me... I made some changes to your tests so that they'll actually run on-disk (ie, exercise Glob).

Sirherobrine23 pushed a commit to Sirherobrine23/gitea-runner that referenced this pull request Sep 28, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | Type | Update |
|---|---|---|---|---|---|
| [github.com/bmatcuk/doublestar/v4](https://github.com/bmatcuk/doublestar) | `v4.10.0` → `v4.10.2` | ![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fbmatcuk%2fdoublestar%2fv4/v4.10.2?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fbmatcuk%2fdoublestar%2fv4/v4.10.0/v4.10.2?slim=true) | require | patch |
| [github.com/ulikunitz/xz](https://github.com/ulikunitz/xz) | `v0.5.16` → `v0.5.17` | ![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fulikunitz%2fxz/v0.5.17?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fulikunitz%2fxz/v0.5.16/v0.5.17?slim=true) |  | patch |
| nginx | `62ff208` → `df221db` |  |  |  | digest |

---

### Release Notes

<details>
<summary>bmatcuk/doublestar (github.com/bmatcuk/doublestar/v4)</summary>

### [`v4.10.2`](https://github.com/bmatcuk/doublestar/releases/tag/v4.10.2): Better support for Windows "Junctions"

[Compare Source](bmatcuk/doublestar@v4.10.1...v4.10.2)

Has improved support for reading "junctions" in Windows (ie, Windows' version of symlinks).

Thanks [@&#8203;x0Lazarus](https://github.com/x0Lazarus) for the PR!

#### What's Changed

- Fix Windows junction traversal with Go 1.23 and later by [@&#8203;x0Lazarus](https://github.com/x0Lazarus) in [#&#8203;117](bmatcuk/doublestar#117)

#### New Contributors

- [@&#8203;x0Lazarus](https://github.com/x0Lazarus) made their first contribution in [#&#8203;117](bmatcuk/doublestar#117)

**Full Changelog**: <bmatcuk/doublestar@v4.10.1...v4.10.2>

### [`v4.10.1`](https://github.com/bmatcuk/doublestar/releases/tag/v4.10.1): Fixed issue with alternatives and character classes

[Compare Source](bmatcuk/doublestar@v4.10.0...v4.10.1)

There was an issue where commas or ending curly brackets inside a character class would cause code looking for the next alternative (commas) or the end of alternatives (ending curly brackets) to erroneously match those characters inside the character classes.

Thanks to [@&#8203;sidsri14](https://github.com/sidsri14) for the fix!

#### What's Changed

- fix brace alternation scanning with character classes by [@&#8203;sidsri14](https://github.com/sidsri14) in [#&#8203;115](bmatcuk/doublestar#115)

#### New Contributors

- [@&#8203;sidsri14](https://github.com/sidsri14) made their first contribution in [#&#8203;115](bmatcuk/doublestar#115)

**Full Changelog**: <bmatcuk/doublestar@v4.10.0...v4.10.1>

</details>

<details>
<summary>ulikunitz/xz (github.com/ulikunitz/xz)</summary>

### [`v0.5.17`](ulikunitz/xz@v0.5.16...v0.5.17)

[Compare Source](ulikunitz/xz@v0.5.16...v0.5.17)

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - Between 12:00 AM and 03:59 AM, only on Monday (`* 0-3 * * 1`)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xOTEuMiIsInVwZGF0ZWRJblZlciI6IjQzLjE5MS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

---------

Co-authored-by: silverwind <2021+silverwind@noreply.gitea.com>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1254
Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com>
Co-authored-by: Renovate Bot <renovate-bot@gitea.com>
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.

ValidatePattern and Match disagree about commas inside character classes in brace alternations

2 participants