Skip to content

fix(datadog_filter): make wildcard regexes match across newlines#1855

Open
Stunned1 wants to merge 3 commits into
vectordotdev:mainfrom
Stunned1:fix/wildcard-regex-newline
Open

fix(datadog_filter): make wildcard regexes match across newlines#1855
Stunned1 wants to merge 3 commits into
vectordotdev:mainfrom
Stunned1:fix/wildcard-regex-newline

Conversation

@Stunned1

@Stunned1 Stunned1 commented Jul 8, 2026

Copy link
Copy Markdown

Summary

wildcard_regex compiled Datadog wildcard queries into ^...$ patterns where . cannot match \n and $ anchors at the absolute end of the string. As a result, queries like field:* or field:*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 is regex::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:*some and 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, so foo*bar failed to match "foo\nbar". The trailing-newline symptom from the issue does not affect word_regex (it has no ^...$ anchors), but wildcard-across-newline does.

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, do
  • Performance

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

  • New unit tests in src/datadog/filter/regex.rs covering trailing newlines, embedded newlines, and no-over-match cases (*some must still not match "here is some\n"; exact patterns are unchanged).
  • New end-to-end cases in the match_datadog_query tests exercising the real query paths (@a:*, @a:*some*, multi-line values, default-field foo*bar).
  • Verified the new regression tests fail without the fix and pass with it.
  • ./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?

  • Yes. Please add a changelog fragment based on
    our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

References

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
@Stunned1
Stunned1 requested a review from a team as a code owner July 8, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

datadog_filter: wildcard_regex fails to match strings with trailing newline

1 participant