fix(datadog_filter): make wildcard regexes match across newlines#1855
Open
Stunned1 wants to merge 3 commits into
Open
fix(datadog_filter): make wildcard regexes match across newlines#1855Stunned1 wants to merge 3 commits into
Stunned1 wants to merge 3 commits into
Conversation
Wildcard patterns compiled by wildcard_regex produced ^...$ regexes where . cannot match \n, so any value with a trailing or embedded newline never matched (e.g. query 'field:*' on value "hello\n"). word_regex had the same defect for wildcards spanning newlines. Enable the (?s) DOTALL flag so *-derived .* matches any character, including newlines. Non-wildcard parts of the pattern are escaped literals and are unaffected. Fixes vectordotdev#1824
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wildcard_regexcompiled Datadog wildcard queries into^...$patterns where.cannot match\nand$anchors at the absolute end of the string. As a result, queries likefield:*orfield:*some*silently failed to match any value with a trailing newline (common in Lambda, container stdout, and other line-delimited sources) or with embedded newlines.This applies the fix proposed in #1824: enable the
(?s)(DOTALL) flag so the.*derived from*matches any character, including\n. Everything else in the generated pattern isregex::escaped literal text, so(?s)only affects the wildcard segments. The issue's alternative suggestion (^{}\n?$) was evaluated and rejected: it does not fix embedded newlines (field:*would still fail on multi-line values) and it wrongly loosens matching (field:*someand even exact patterns would match values with a trailing newline).The same flag is applied to
word_regex(default-field queries), which had the same defect in a different form: a*-derived.*could not span a newline, sofoo*barfailed to match"foo\nbar". The trailing-newline symptom from the issue does not affectword_regex(it has no^...$anchors), but wildcard-across-newline does.Change Type
Is this a breaking change?
How did you test this PR?
src/datadog/filter/regex.rscovering trailing newlines, embedded newlines, and no-over-match cases (*somemust still not match"here is some\n"; exact patterns are unchanged).match_datadog_querytests exercising the real query paths (@a:*,@a:*some*, multi-line values, default-fieldfoo*bar)../scripts/checks.sh: format_check, clippy (-D warnings, all features, all targets), tests (workspace), and vrl_tests all pass locally.Does this PR include user facing changes?
our guidelines.
Checklist
run
dd-rust-license-tool writeand commihere.References