feat(cli): strip internal whitespace from @file / @- transaction input#341
Open
prasanna-anchorage wants to merge 1 commit into
Open
feat(cli): strip internal whitespace from @file / @- transaction input#341prasanna-anchorage wants to merge 1 commit into
prasanna-anchorage wants to merge 1 commit into
Conversation
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>
Contributor
There was a problem hiding this comment.
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. |
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
--transaction @fileand--transaction @-now strip every ASCII whitespace byte from the buffer, not just leading/trailing edges.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 newreads_from_file_and_strips_internal_whitespaceandstrip_ascii_whitespace_preserves_non_ascii)-t @tx.hexand confirmed identical output to the inline form