Skip to content

fix(os/gfile): keep MatchGlob globstar matching separator-aware on windows - #4961

Merged
lingcoder merged 2 commits into
gogf:masterfrom
b84330808:fix/gfile-matchglob-windows
Nov 6, 2026
Merged

lingcoder merged 2 commits into
gogf:masterfrom
b84330808:fix/gfile-matchglob-windows

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Test_MatchGlob_InvalidGlobstar fails on Windows (CI only runs on Linux, so it doesn't show up there).

The globstar branch of MatchGlob converts both the pattern and the name to / separators and then calls filepath.Match. On Windows filepath.Match only treats \ as a separator, so after the conversion * also matches /, e.g. MatchGlob("a**b", "a/b") returns true.

This uses path.Match at the three globstar call sites, since the strings there are already /-separated. On Unix-like systems nothing changes, because path.Match and filepath.Match behave the same there. I also added two Windows-path cases to Test_MatchGlob_WindowsPath; both tests fail on master on Windows and pass with this change.

…ndows

The globstar path of MatchGlob normalizes both pattern and name to "/"
separators and then calls filepath.Match. On Windows filepath.Match only
treats "\" as a separator, so "*" matched across "/" there and, for
example, "a**b" matched "a/b". Use path.Match on the normalized paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Malformed glob patterns now return path.ErrBadPattern instead of filepath.ErrBadPattern across three matching paths, breaking existing errors.Is checks and requiring error translation plus identity tests.

1 open issue
What changed in this PR

This PR fixes Windows separator handling in GoFrame’s gfile.MatchGlob, preventing ordinary * wildcards from matching across normalized path separators in globstar patterns.

Changes:

  • Uses path.Match at three globstar matching sites where paths are already normalized to /.
  • Adds two Windows-path regression cases covering wildcard separator boundaries.
File Description
os/​gfile/​gfile_z_unit_match_test.go Adds regression tests ensuring wildcards do not cross Windows path separators.
os/​gfile/​gfile_match.go Switches normalized globstar matching to path.Match and updates explanatory comments.

Review effort: Balanced

Comment thread os/gfile/gfile_match.go Resolved
@hailaz
hailaz requested a review from gqcn November 5, 2026 06:53
@lingcoder
lingcoder force-pushed the fix/gfile-matchglob-windows branch from 91456ac to 9b4d8ef Compare November 6, 2026 01:36
@lingcoder
lingcoder requested review from lingcoder and removed request for gqcn November 6, 2026 01:46

@lingcoder lingcoder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lingcoder
lingcoder merged commit 75b673e into gogf:master Nov 6, 2026
6 of 15 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.

3 participants