Skip to content

Fix stems handling.#126089

Open
cincuranet wants to merge 4 commits intodotnet:mainfrom
cincuranet:wrong-stems
Open

Fix stems handling.#126089
cincuranet wants to merge 4 commits intodotnet:mainfrom
cincuranet:wrong-stems

Conversation

@cincuranet
Copy link
Contributor

@cincuranet cincuranet commented Mar 25, 2026

Fixes #97333.

FrameData is a struct, so FrameData frame = Frame; (line 38 in Linear, line 36 in Ragged) shallow-copies value fields but copies the _stemItems list reference. Both the old and new frame then share the same List<string>, so .Add() mutates it for all frames.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes incorrect stem accumulation in Microsoft.Extensions.FileSystemGlobbing caused by struct frame copies sharing the same _stemItems list reference, ensuring each frame has isolated stem state and adding a regression test for sibling wildcard directories.

Changes:

  • Clone FrameData on PushDirectory in both linear and ragged pattern contexts to avoid sharing stem list state across frames.
  • Remove PatternContextRagged.PopDirectory stem-item mutation workaround (no longer needed with isolated frame state).
  • Add a functional regression test covering multiple sibling wildcard directories to validate correct stem output.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/PatternContexts/PatternContextLinear.cs Uses Frame.Clone() to prevent shared stem list state across stack frames.
src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/PatternContexts/PatternContextRagged.cs Switches to frame cloning and removes pop-time stem mutation to fix stem correctness.
src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/FunctionalTests.cs Adds regression test asserting stems don’t accumulate across sibling wildcard directories.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@cincuranet cincuranet requested review from a team, mrek-msft, rosebyte and svick March 26, 2026 10:10
}

[Fact]
public void StemIsCorrectForMultipleWildcardSiblingDirectories()
Copy link
Member

Choose a reason for hiding this comment

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

AFAICT, this tests PatternContextLinear. Shouldn't there be also a test for PatternContextRagged ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileSystemGlobbingMatcher produces wrong stems

4 participants