fix: use UTF-8 byte length for Stellar MEMO_TEXT validation in RemittanceForm - #1587
Open
waterWang wants to merge 2 commits into
Open
fix: use UTF-8 byte length for Stellar MEMO_TEXT validation in RemittanceForm#1587waterWang wants to merge 2 commits into
waterWang wants to merge 2 commits into
Conversation
…anceForm
Replace character-count validation (`memo.length > 28`) with UTF-8 byte-length
validation (`new TextEncoder().encode(memo).length > 28`) to correctly enforce
Stellar's 28-byte MEMO_TEXT limit. Multibyte characters (accents, emoji, CJK)
that pass the 28-character check but exceed 28 bytes now show a clear error
message at validation time instead of failing at transaction submission.
Changes:
- `validateForm` now checks `TextEncoder().encode(memo).length` instead of `memo.length`
- Removed `maxLength={28}` attribute from textarea in favor of byte-aware validation
- Character counter updated to show byte count ("{n}/28 bytes")
- Added test for multibyte rejection (15 × ñ = 30 bytes)
- Updated existing test assertions for new error message and byte counter
Closes LabsCrypt#1074
Open
5 tasks
jsdom does not expose the TextEncoder global on all Node versions, which breaks unit tests in RemittanceForm that now use TextEncoder().encode() for UTF-8 byte-length memo validation. Polyfill from node:util when the global is absent.
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.
Fix Stellar MEMO_TEXT validation: use UTF-8 byte length instead of character count
Closes #1074
Problem
The memo field validated by character count (
memo.length > 28), but StellarMEMO_TEXTcaps at 28 bytes, not 28 characters. Multibyte UTF-8 memos (accented characters, emoji, CJK) could pass the 28-character check and still exceed 28 bytes, failing at transaction submission time.Changes
validateForm: Replacedmemo.length > 28withnew TextEncoder().encode(memo).length > 28(UTF-8 byte-length check)maxLength={28}attribute (character-level cap) in favor of byte-aware validation at submit time{memo.length}/28 charactersto{new TextEncoder().encode(memo).length}/28 bytesAcceptance Criteria
new TextEncoder().encode(memo).length <= 28)Files modified
frontend/src/app/components/remittance/RemittanceForm.tsx— validation, textarea, counterfrontend/src/app/components/remittance/RemittanceForm.test.tsx— updated + new test