Skip to content

feat(cli): strip internal whitespace from @file / @- transaction input#341

Open
prasanna-anchorage wants to merge 1 commit into
mainfrom
cli-strip-whitespace-tx-input
Open

feat(cli): strip internal whitespace from @file / @- transaction input#341
prasanna-anchorage wants to merge 1 commit into
mainfrom
cli-strip-whitespace-tx-input

Conversation

@prasanna-anchorage
Copy link
Copy Markdown
Contributor

Summary

  • --transaction @file and --transaction @- now strip every ASCII whitespace byte from the buffer, not just leading/trailing edges.
  • Lets users paste line-wrapped hex (or base64) straight out of a block explorer or wrapped terminal without manual cleanup.
  • The 10 MB raw-read limit still applies, so a whitespace-padded file cannot bypass it. Non-ASCII whitespace (NBSP and friends) is intentionally preserved so it surfaces as a decode error instead of being silently swallowed.
  • Uses str::split_ascii_whitespace().collect() — built-in, no extra allocation per chunk.

Test Plan

  • cargo test -p parser_cli tx_input:: (9 unit tests, including new reads_from_file_and_strips_internal_whitespace and strip_ascii_whitespace_preserves_non_ascii)
  • Manually decoded a wrapped Tron VoteWitness tx via -t @tx.hex and confirmed identical output to the inline form

Hex and base64 transaction strings can't legitimately contain whitespace, so
when a user pastes line-wrapped hex from a block explorer or wrapped terminal
into a file (or pipes it via stdin) we now strip every ASCII-whitespace byte
from the buffer instead of only trimming the edges. The 10 MB size limit is
still applied to the raw read, so a whitespace-padded file can't bypass it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 28, 2026 17:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates CLI transaction input handling so --transaction @file and --transaction @- can accept wrapped transaction strings by stripping ASCII whitespace after reading, while preserving the existing raw 10 MB read limit.

Changes:

  • Replaces edge-only trimming for @ inputs with full ASCII-whitespace stripping.
  • Adds helper documentation explaining why Unicode whitespace is preserved.
  • Adds unit tests for wrapped file input and non-ASCII preservation behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +99 to +101
// Multi-byte UTF-8 (e.g. en dash) must pass through unchanged so we
// never silently corrupt input that happens to land in `@file` mode.
assert_eq!(strip_ascii_whitespace("a b\tc\nd \u{2013}"), "abcd\u{2013}");
Comment on lines +7 to +12
//! In all `@` cases, ASCII whitespace (spaces, tabs, CR, LF) is stripped from
//! the buffer since the transaction string itself (hex / base64) cannot
//! legitimately contain it — this lets users paste line-wrapped hex from
//! block explorers or terminal emulators without manual cleanup. The 10 MB
//! size limit is applied to the raw read so a whitespace-padded file can't
//! bypass it.
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