Repository navigation
fix(search): match brace alternation and character classes in globs - #1111
Open
buguoshixc wants to merge 1 commit into
Open
buguoshixc wants to merge 1 commit into
buguoshixc wants to merge 1 commit into
Conversation
A glob entry now expands `{a,b}` (nestable, a branch may carry `/`), reads
`[abc]`, `[a-z]`, `[!abc]`/`[^abc]` and backslash-escaped bytes, and is
compiled once per request before any path is opened. A pattern that cannot be
parsed is refused as INVALID_ARGUMENT with the field, its index and a
nextAction, instead of being matched literally and reported as zero results.
The old matcher recognised only `?` and `*`, so `{`, `[` and `\` were literal
bytes no name contains: `**/{README*,links.json}` returned matchedTotal 0 with
scanComplete true while the same two globs as separate entries returned every
file.
Refs T-Auto#1110
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.
Closes #1110
What was wrong
ops_glob.pattern,ops_grep.globandops_replace.globshared one matcher that compared bytes and recognised only?and*:segment_matchinnative/crates/ops-search/src/lib.rscompared every other byte literally, andPatterns::newsplit on/without expanding anything. So{,,,},[,]and\were literal bytes that no file name contains — and the call reported success.The issue's two reproductions on this machine before the change (a fixture with
README.md,links.json,src/README.md,src/links.json, each containing the wordlinks):ops_glob {"pattern": ["**/{README*,links.json}"]}matchedTotal: 0,scanComplete: truematchedTotal: 4, same items as the split formops_glob {"pattern": ["**/README*", "**/links.json"]}matchedTotal: 4matchedTotal: 4ops_grep {"pattern": "links", "glob": ["**/{README.md,links.json}"], "outputMode": "summary"}files: 0; matches: 0files: 4; matches: 5ops_grep {"pattern": "links", "glob": ["**/README.md", "**/links.json"], "outputMode": "summary"}files: 4; matches: 5files: 4; matches: 5The receipt for the first row was
scanComplete: true,matchedTotal: 0andskipReasons.pattern— indistinguishable from "this repository has no such file", which is what made the bug costly.The change
One matcher, compiled once per request, shared by all three entries. Nothing is compiled per file and nothing is allocated while matching.
native/crates/ops-search/src/glob.rs(new, 432 implementation lines)/, empty branches allowed, a 256-alternative budget that aborts the expansion instead of computing it), segment compilation ([abc],[a-z],[]],[!abc]/[^abc],\escapes,**), and the byte matcher thatlib.rsused to hold. A malformed entry becomes aFault, which is the only thing that knows the field name and index.native/crates/ops-search/src/patterns.rsPatternsnow owns its compiled alternatives instead of borrowing&'a [String];compile(field, patterns) -> Result<Self>replaces the infalliblenew;shallow()is judged on the expanded alternatives, so{*.md,src/*.ts}no longer prunessrc/.native/crates/ops-search/src/lib.rsglob_segments/segment_match;files_fortakes&Patterns;replace_withcompiles before it walks.native/crates/ops-search/src/scan.rswalk,walk_indexed,apply_batchandvisittake&Patterns. TheglobCompileprofile bucket is unchanged; it is recorded where the compile now happens (the entry), exactly once per request.native/crates/ops-search/src/search.rsglob_withandgrep_withcompile beforetarget(), beforeauthorize_pathand before any traversal;walk_requestpasses the compiled value down.native/crates/ops-search/src/scan_tests.rs,candidates_tests.rsskipReasons.pattern, with no new vocabulary.src/capabilities/file.tsINVALID_ARGUMENT, not an empty result.test/search-coverage.test.mjs,test/linux-args.test.mjs,test/file-contract.test.mjsdocs/component-reference.md,docs/组件参考.md,docs/CHANGELOG.md?/class caveat, the refusal contract, and the Unreleased entry.Behaviour changes worth stating in the changelog and in the docs:
{,[and\now have meaning. A pattern that used to match the literal text{a}has to say\{a\}.INVALID_ARGUMENT, naming the field and index (pattern[0],glob[1]) and carryingnextAction:Escape a literal "{", "}", "[", "]", "," or "\" with a backslash, or split the entry into separate array items.pattern[0] has an unclosed "{" (escape a literal "{" as "\{")pattern[1] has an unclosed "["pattern[0] has an invalid character range "z-a"pattern[2] ends with a dangling "\"pattern[0] expands to more than 256 alternatives; split it into separate array itemspattern[0] would make the request expand to more than 512 alternatives; split it into separate array items(the request-wide ceiling)Deliberately not done:
?and character classes still consume one byte, not one character (so non-ASCII names need*); a class is byte-based, not a Unicode property; an escaped/cannot match because names are split on/before a segment is matched; empty entries, empty segments and./..are left exactly as they are (that surface belongs to the in-flight #802); result fields,scanComplete/matchedTotal/matchedObserved, theskipReasonsvocabulary, paging and continuation are untouched; no new dependency, no build/CI/manifest change,src/ptc/ops-tools.json(which carries no descriptions) was not regenerated.Relationship to the in-flight #802
#802 (
fix/797-unmatchable-glob-entries) is not merged intoorigin/main(checked:git merge-base --is-ancestor origin/fix/797-unmatchable-glob-entries origin/mainfails; the branch is one commit ahead). It reserves the same seam —patterns.rsvalidation pluspattern[i] must be …messages raised from theglob,grepandreplaceentries.This PR keeps a single validation entry point,
Patterns::compile, and raises its own faults through one helper (Fault::failure) that already knows the field name and index. #802'sfirst_invalid/EntryFault/invalid_messagechecks can run inside that entry (or immediately before it) and keep their message shape untouched; whoever merges second extends this one path rather than adding a second, parallel check. There is no other preflight for glob syntax anywhere in the tree.Validation
docs/CHANGELOG.md## [Unreleased]has one English and one Chinese entrycomponent-reference.md,组件参考.md)package.jsonversion oroptionalDependencieschangetest/file-contract.test.mjspins what they now say (the field help stays under the 200-byte cap enforced there)pull_request-triggeredCI requiredrun exists but is parked ataction_required— the first run from a fork waits for a maintainer to approve it. Its URL is below; it has no conclusion, and every number above is a local reading, not CI.That is the required
pull_requestevent for this branch. It is parked ataction_required— the first run from a fork waits for a maintainer to approve it — so it has no conclusion and this PR is not claiming one. Everything quoted above was measured locally on the commit that was pushed.All five failures are pre-existing on this host and reproduce identically on an untouched
origin/mainworktree (same commit1caf4df2, built and run side by side):bash-ipc3/8 andbash-ipc-roots4/4 fail withPinned Bash is unavailable … set DSH_OPS_TEST_BASH(no provisioned MSYS payload on this machine),linux-paths1/8 andwsl-prepare-merge1/3 fail on Windows path/WSL fixtures, and the seven skips need frozen archives or POSIX-only subjects. None of them touchesops-search, and none is searched by this change. Every suite this PR touches passes.What fails without this change
glob::tests::braces_alternate_including_nested_and_empty_branches— revert the expansion and{a,b}is one literal segment again.glob::tests::escapes_and_classes_are_literal_where_the_syntax_needs_them— revert class parsing or the escape arm and[]],[!b],[a-z],\[,\{stop selecting what they select.glob::tests::malformed_patterns_name_the_entry_and_carry_advice— revert any fault mapping and the exact message,nextActionor code stops matching.glob::tests::the_budget_stops_nested_expansion_before_it_explodes— remove the budget and 20 groups of two either hang or produce 1 048 576 alternatives instead of the refusal.glob::tests::a_brace_inside_a_class_is_a_member_not_a_group— make the expander ignore classes and[{]becomes an alternation.glob::tests::recursive_and_literal_double_star_stay_distinct— treat every*run as**and the escaped form starts matching paths.patterns::tests::compiled_patterns_match_original_inclusions_exclusions_and_path_segments— the old matcher is kept verbatim in the test as a reference over every pattern that carries no new syntax; any drift in ordinary matching turns it red.patterns::tests::shallow_is_judged_on_expanded_alternatives— judgeshallow()on the raw text again and{*.md,src/*.ts}claims one segment, so the walk prunessrc/and deep files silently disappear.patterns::tests::compiles_once_and_reports_the_field_it_was_given— drop the field/index argument andglob[0]becomespattern[0].patterns::tests::the_request_budget_counts_every_entry_not_only_one— remove the 512 ceiling and three 256-alternative entries compile.scan::scan_tests::brace_selections_still_report_only_the_existing_pattern_reason— invent a skip reason for expanded entries and both the count and the vocabulary assertion fail.search-coverage“brace alternation, character classes and escapes select exactly what separate entries select” — this is the issue's own reproduction; before the change the first row is0 !== 4.linux-args“malformed glob syntax is refused in preflight instead of matching nothing” — before the change these five calls returncompletedwith zero items; the test asserts the code, the exact message (with theglob:/grep:/replace:prefixdispatchadds),phase: "preflight",effectState: "none"andnextAction.file-contract— the new assertions fail if any of the three descriptions loses the syntax list or the refusal clause.search-profiling(existing) — move the compile out of the profiled bucket andglobCompile.callsstops being 1.Environment
origin/mainat1caf4df2(Merge pull request #1106), branchfix/1110-glob-alternation-and-classesnpm ci --ignore-scriptsfrom the npm registry, thennpm run build/npm run build:ptcfrom this checkoutD:/rust) because this account's profile path is non-ASCII and MinGWldcannot openC:\Users\…\.rustup\…from a linker response file; andTEMP/TMPpoint atD:/tmpfor the same reason, sincefs.cpSyncintoC:\Users\…\AppData\Local\Tempfails withEIO, Access is deniedfor the packaging suites. With the system temp path, 12 suites fail for that reason alone; with an ASCII one, 5 do.