Fix ** glob pattern not matching files in root directory (Fixes #2355) - #2500
Fix ** glob pattern not matching files in root directory (Fixes #2355)#2500amanmaurya92 wants to merge 3 commits into
Conversation
This fixes issue dart-lang#2355 by updating the DoubleStarNode regex evaluation to treat a leading or trailing slash as optional when matching zero directories, and flattens AST nodes during list generation.
There was a problem hiding this comment.
Code Review
This pull request improves glob matching logic to correctly match files in the root directory when using double-star patterns (e.g., **/foo matching foo). It updates SequenceNode._toRegExp() to handle a DoubleStarNode followed by a slash literal, flattens nested SequenceNode instances in _join, and adds corresponding tests. The reviewer pointed out that the substring operation in SequenceNode._toRegExp() assumes the regex always ends with [^]*, which is fragile, and suggested adding a defensive check to ensure it ends with [^]* before performing the substring.
|
I believe this is missing more edge test cases, for example: |
f50176b to
929ae5c
Compare
|
The previous regex replacement was too loose. I've updated the logic so the optional slash for To ensure everything behaves exactly as expected, I've added the following tests now:
|
This fixes issue #2355 by updating the DoubleStarNode regex evaluation to treat a leading or trailing slash as optional when matching zero directories, and flattens AST nodes during list generation.
Fixes #2355.
Changes:
SequenceNode._toRegExp()inast.dartto make the trailing slash following aDoubleStarNodeoptional ((?:[^]*/)?) when matching zero directories (e.g. allowing**/filenameto matchfilename).list_tree.dart's_join()method to correctly position adjacentSequenceNodeelements so they are processed properly.match_test.dartandlist_test.dartto ensure**/foomatchesfooand correctly evaluates when**corresponds to 0 directories.Contribution guidelines:
dart format.Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.