Repository navigation
[DaC] [Bug] Stop appending trailing newline to query on TOML export - #6865
Closed
Varshith-Kali wants to merge 1 commit into
Closed
Varshith-Kali wants to merge 1 commit into
Varshith-Kali wants to merge 1 commit into
Conversation
toml_write wrapped query/threat_query as '''\n<query>\n'''. TOML only trims the newline immediately following the opening delimiter, so the trailing newline survived parsing and every export/import round-trip appended a phantom newline to the query in Kibana (no accumulation thanks to the write-time strip, but the imported value never matched the source). Write '''\n<query>''' instead so the parsed value is byte-identical to the written query. threat_query had the identical pattern and is fixed the same way. Tests: - new test_query_round_trip_adds_no_trailing_newline asserts exact round-trip equality (no strip masking) for query and threat_query, including a double round-trip stability check - removed the formatted-side .strip() in compare_formatted that was masking this bug; the two pre-existing formatter tests now fail without the fix and pass with it Fixes elastic#6081. Signed-off-by: Varshith Puli <pulivarshit@gmail.com
Varshith-Kali
requested review from
Mikaayenson and
eric-forte-elastic
as code owners
September 23, 2026 16:49
|
❌ Author of the following commits did not sign a Contributor Agreement: Please, read and sign the above mentioned agreement if you want to contribute to this project |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
This has been closed due to inactivity. If you feel this is an error, please re-open and include a justifying comment. |
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.
What
Every export→import round-trip of a rule added a phantom trailing newline to
query(andthreat_query):toml_write()emittedquery = '''\n<query>\n'''. TOML only trims the newline immediately following the opening delimiter, so the trailing\nbefore the closing'''survived parsing — the imported query never matched the source.Fix
Emit
'''\n<query>'''(no trailing pad) for bothqueryandthreat_queryindetection_rules/rule_formatter.py, with an explanatory NOTE comment. The intentional write-time.strip()standardization is untouched (repo lint policy, acknowledged in the issue thread).Fixes #6081.
Tests
tests/test_toml_formatter.py: 8/8 pass (7 pre-existing + 1 new). The newtest_query_round_trip_adds_no_trailing_newlineasserts exact (strip-free) round-trip equality forqueryandthreat_queryacross 5 shapes (single-line, multi-line, backslash paths, quote mixes) plus double round-trip stability. Notably, I removed a.strip()in thecompare_formattedhelper that was masking this bug — A/B via stash: without the fix, 3 tests fail (the new one plustest_formatter_ruleandtest_normalization, which now correctly catch it); with the fix, all pass. Ruff check and format clean on both changed files.One pre-existing limitation, unchanged and out of scope: a query literally containing
'''cannot round-trip (raw insertion into a TOML literal string) — fails identically before/after this change.