fix(core): escape literal wildcards and anchor patch insertions - #41335
Open
chirag-gamer wants to merge 2 commits into
Open
fix(core): escape literal wildcards and anchor patch insertions#41335chirag-gamer wants to merge 2 commits into
chirag-gamer wants to merge 2 commits into
Conversation
Patterns like \* and \? were always treated as wildcards because the only escape character was collapsed to a path separator before regex escaping. Protect escaped globs (\\*, \\?, \\\\) first so permission rules can match resources containing literal *, ? or backslash.
A chunk with a located changeContext but no old lines used to be inserted at the end of the file regardless of the anchor. Insert after the context line instead, keeping end-of-file append for chunks without an anchor.
This was referenced Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #41333
Type of change
What does this PR do?
Fixes the two things from #41333.
First, the wildcard matcher in
packages/core/src/util/wildcard.ts(and the legacy copy inpackages/opencode/src/util/wildcard.ts) had no way to match a literal*,?, or\in a permission resource. The only escape character was collapsed to a path separator before the regex was built, so\*and\?always behaved as wildcards. The change protects\*,\?, and\\before normalization so they match literally; plain\still works as a path separator. One consequence worth flagging: a Windows-style pattern likeC:\Windows\*now means "a file literally named*" instead of "everything inC:\Windows", so patterns should use forward slashes (C:/Windows/*). The tests were updated to use/.Second,
apply_patchignored the@@anchor for pure insertions. A chunk with a change context but no-or context lines (oldLines.length === 0) was always appended at the end of the file, so@@ after the importsfollowed by only+lines landed at the bottom. Insertions now go right after the located context line; chunks without an anchor still append at EOF.How did you verify your code works?
bun test test/wildcard.test.ts test/patch.test.tsinpackages/core: 13 pass, 0 fail.bun test test/util/wildcard.test.tsinpackages/opencode: the 9 wildcard tests pass (the new escape cases plus the existing glob and slash tests). The package test preload in this checkout fails on a missing drizzle-orm subpath, but the wildcard tests themselves all pass.config\?.json,\*,a\\b) against the updated function to confirm literal matching and no regression on the trailing*command rule.Screenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist