Skip to content

feat: add Glob validator with gitignore-style pattern matching#10

Merged
HarshMN2345 merged 8 commits into
mainfrom
feat/glob-validator
May 21, 2026
Merged

feat: add Glob validator with gitignore-style pattern matching#10
HarshMN2345 merged 8 commits into
mainfrom
feat/glob-validator

Conversation

@HarshMN2345
Copy link
Copy Markdown
Member

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 21, 2026

Greptile Summary

This PR introduces a new Globstar validator that accepts gitignore-style glob patterns and matches strings against them using a pure-PCRE engine built from scratch — no dependency on fnmatch(). The two-phase inclusion/exclusion logic (literal inclusions win unconditionally in step 1; wildcard patterns use last-match-wins in step 2) is well-structured and backed by a thorough test suite.

  • src/Validator/Globstar.php: new validator with support for *, **, ?, [abc] character classes, \\ escapes, and ! exclusion prefixes, all converted to PCRE.
  • tests/Validator/GlobstarTest.php: 40+ test methods covering pure inclusions, pure exclusions, mixed modes, re-inclusion chains, edge-case bracket classes, and escaped characters.

Confidence Score: 4/5

Safe to merge with the noted edge-case fixes; core matching logic is correct for all tested patterns.

The regex construction and two-phase inclusion/exclusion logic are correct for all tested scenarios. Two small gaps exist: escape sequences inside bracket classes are not handled, and the middle-** regex fragment relies on greedy backtracking rather than explicit segment-boundary repetition. Neither affects common usage patterns.

The matchGlobstar method in src/Validator/Globstar.php, specifically the bracket-class inner-loop and the middle-** regex fragment.

Important Files Changed

Filename Overview
src/Validator/Globstar.php New Globstar validator implementing gitignore-style glob matching via PCRE regex construction. Core logic is sound and well-tested; minor issues with docblock class name, \] escape handling inside bracket classes, and the (?:.+/)? regex fragment for middle ** relying on PCRE backtracking rather than an explicit segment-boundary quantifier.
tests/Validator/GlobstarTest.php Comprehensive test suite covering empty patterns, pure inclusions, pure exclusions, mixed modes, all wildcard forms, character classes (including negation and edge cases), escaped characters, and real-world path patterns. No test for \] inside a bracket class.

Reviews (6): Last reviewed commit: "rename: Glob -> Globstar" | Re-trigger Greptile

Comment thread src/Validator/Glob.php Outdated
Comment thread src/Validator/Glob.php Outdated
Comment thread src/Validator/Glob.php Outdated
Comment thread src/Validator/Globstar.php
@HarshMN2345 HarshMN2345 merged commit b4ee60d into main May 21, 2026
3 of 4 checks passed
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.

2 participants