Fix SEP-0011 MEMO_TEXT escaping to use C-style \xNN UTF-8 byte format#140
Merged
Conversation
Encode now delegates to TxRepHelper.escapeString instead of jsonEncode, producing SEP-0011 compliant \xNN byte escapes for non-ASCII memos. Decode accepts both the new format and legacy \uNNNN blobs from older SDK versions. Also emits \r and \t as short escapes in escapeString. Adds test coverage for the new and legacy formats.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #140 +/- ##
==========================================
+ Coverage 88.98% 89.07% +0.09%
==========================================
Files 623 623
Lines 28711 28733 +22
==========================================
+ Hits 25548 25594 +46
+ Misses 3163 3139 -24
🚀 New features to boost your workflow:
|
Adds tests for previously uncovered error paths and legacy decode branches in the SEP-0011 facade: missing or malformed tx.memo.text, unknown memo type, missing TxRep type header, fee-bump inner type mismatch, V0 envelope up-conversion with and without time bounds, and the legacy tx.timeBounds._present decode format.
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
Bug fix. The SEP-0011 facade encoded
MEMO_TEXTviajsonEncode, producing\uNNNNUnicode escapes for non-ASCII characters. SEP-0011 specifies C-style\xNNUTF-8 byte escapes (e.g."caf\xc3\xa9"rather than"caf\u00e9"), so output from this SDK could fail to parse in strict implementations.Backwards compatibility
Encoded output for non-ASCII
MEMO_TEXTchanges byte-for-byte; consumers comparing TxRep strings or using golden files will see diffs. Decoding remains compatible with legacy\uNNNNoutput from older SDK versions.Changes
lib/src/sep/0011/txrep.dart:_encodeMemonow delegates toTxRepHelper.escapeString._decodeMemotriesunescapeStringfirst and falls back tojsonDecodeonly when an unescaped\uNNNNsequence is detected (via lookbehind regex), so legacy TxRep blobs from older SDK versions still parse. Both decode paths wrapFormatExceptionas a TxRep-styleException.lib/src/xdr/txrep_helper.dart:escapeStringnow emits\rand\tas C-style short escapes;unescapeStringdecodes them.\uNNNNdecode, newline, 4-byte UTF-8 (emoji), empty string, literal backslash-u (heuristic edge case), 28-byte UTF-8 boundary, legacy decode with embedded quote escapes, and\r/\tround-trips at the helper level.