Skip to content

fix(rstix): make pattern printer formatting infallible - #638

Merged
mostafa merged 4 commits into
timescale:mainfrom
SecurityEnthusiast:fix/rstix-pattern-print-infallible
Oct 29, 2026
Merged

mostafa merged 4 commits into
timescale:mainfrom
SecurityEnthusiast:fix/rstix-pattern-print-infallible

Conversation

@SecurityEnthusiast

Copy link
Copy Markdown
Contributor

Summary

Removes seven production write!(…).expect("fmt") calls from the STIX pattern canonical printer; output is unchanged.

Test plan

  • [*] cargo test -p rstix --features pattern --locked pattern::print

Replace write!(String).expect("fmt") in the canonical pattern printer
with String appends and a small hex helper; document in CHANGELOG.

@mostafa mostafa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment only. The printer output matches the old write! formatting, and the seven expect("fmt") calls are gone. Integers, repeat counts, indices, and floats still go through Display. Booleans still print true and false. Hex is still two lowercase digits. cargo fmt --all -- --check, cargo clippy -p rstix --all-targets --all-features -- -D warnings, and cargo doc -p rstix --all-features --locked --no-deps are clean. cargo test -p rstix --features pattern --locked pattern::print passes (4 tests).

Non-blocking: those tests still pass if hex is printed in uppercase. See the comment on push_hex_byte.

CI, Docs, and Docs audit are action_required until a maintainer approves the fork workflows. This branch and #637 both insert a heading at the top of ## [Unreleased], so the second one to merge needs a rebase.

Comment thread crates/rstix/src/pattern/print.rs Resolved
Assert the printed form of hex, a boolean, an index, an integer-valued float, and REPEATS. Semantic equality accepts any spelling that parses to the same value.

@mostafa mostafa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pushed 90a17e5b. canonical_spelling_pins_literals parses h'FFD8', true, sections[0], 7.0, and REPEATS 2 TIMES, and requires the printed string h'ffd8', true, [0], 7, and REPEATS 2 TIMES. Uppercase hex fails that test. fmt and clippy on rstix are clean.

@mostafa

mostafa commented Oct 29, 2026

Copy link
Copy Markdown
Member

Merged main in b3e9c464. The pattern printer entry stays above the confidence scale entry from #637, and the branch merges cleanly.

@mostafa
mostafa merged commit d35fbfc into timescale:main Oct 29, 2026
22 checks passed
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.

2 participants