Repository navigation
Fix ** glob pattern not matching files in root directory (Fixes #2355) - #2500
amanmaurya92 wants to merge 5 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:
|
natebosch
left a comment
There was a problem hiding this comment.
Changing this behavior could have significant impact in the ecosystem. I suspect most of that should be positive impact, but we'll want some discussion about the tradeoffs of changing the behavior before we go forward with a more detailed code review. We'll discuss a bit on the linked issue then I will revisit the code changes.
| - Fix `**` matching for directory boundaries so it can match zero directories | ||
| at the start of the string or following a separator. | ||
|
|
There was a problem hiding this comment.
[nit]
| - Fix `**` matching for directory boundaries so it can match zero directories | |
| at the start of the string or following a separator. | |
| - Fix `**` matching for directory boundaries so it can match zero directories | |
| at the start of the string or following a separator. |
929ae5c to
a4c8aa2
Compare
a4c8aa2 to
aff7a1e
Compare
|
@natebosch Sure, I'll keep an eye on the discussion in the issue. If you prefer, I can turn this into a draft or close it for now. |
|
I took a look through the code, I think we can simplify things a bit. In the end I think it's easier to open a separate PR with my suggested version of the code so I opened #2506. I've merged in your commit for the tests so your authorship for this change will be reflected in the landed commit. The main simplification comes from not having to inspect and edit parts of the regex strings, instead including the Thanks for the demonstration of a fix for this 😄 |
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.