Skip to content

Match filter_by keys exactly before treating them as globs - #69750

Merged
dwoz merged 2 commits into
saltstack:3006.xfrom
ggiesen:fix-60976-filter-by-exact-match
Aug 7, 2026
Merged

dwoz merged 2 commits into
saltstack:3006.xfrom
ggiesen:fix-60976-filter-by-exact-match

Conversation

@ggiesen

@ggiesen ggiesen commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes salt.utils.data.filter_by try an exact key comparison before treating a lookup key as an fnmatch glob, so literal keys that contain glob metacharacters still match their own value.

What issues does this PR fix or reference?

Fixes #60976

Previous Behavior

filter_by ran every lookup_dict key through fnmatch.fnmatchcase, unconditionally treating it as a shell glob. A literal key containing glob metacharacters -- for example the [ and ] in GPU/PCI model strings like GP104GL [Quadro P4000] -- was parsed as a character class, so the identical literal key never matched its own value and filter_by fell through to the default. (The reporter attributed this to spaces; the real trigger is the [...] metacharacters.)

New Behavior

Keys are matched with an exact string comparison first, then the existing fnmatch glob as a fallback. Literal keys (including ones with glob metacharacters) now match, while existing glob patterns are unchanged. The fix is strictly additive -- it can only make a previously-non-matching literal key match. Because grains.filter_by, pillar.filter_by, and match.filter_by all delegate here, they are all fixed.

Merge requirements satisfied?

  • Docs - not applicable
  • Changelog - changelog/60976.fixed.md
  • Tests written/updated - tests/pytests/unit/utils/test_data.py: literal key with [...] metacharacters now matches (pins the bug), glob patterns still match, plain literal keys still match

Commits signed with GPG?

No

salt.utils.data.filter_by ran every lookup_dict key through
fnmatch.fnmatchcase, so a literal key containing glob metacharacters (the
"[" and "]" in GPU/PCI model strings such as "GP104GL [Quadro P4000]")
was parsed as a character class and never matched its own value, falling
through to the default (saltstack#60976). Try an exact string comparison before the
fnmatch fallback. The change is additive: literal keys now match and
existing glob patterns are unaffected. This also covers grains.filter_by,
pillar.filter_by, and match.filter_by, which all delegate here.

Fixes saltstack#60976
@ggiesen
ggiesen requested a review from a team as a code owner July 10, 2026 07:50
@charzl charzl self-assigned this Jul 10, 2026
@dwoz dwoz added the test:full Run the full test suite label Jul 10, 2026
@twangboy twangboy added this to the Sulphur v3006.28 milestone Jul 15, 2026
@dwoz
dwoz merged commit fd37126 into saltstack:3006.x Aug 7, 2026
852 of 854 checks passed

This branch was previously deployed

1 inactive deployment
ci — 3416e4d0 Deployed Jul 29, 2026 by ggiesen via Build Onedir Packages / Windows (x86) #25940
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants