Skip to content

Fix SEP-0011 MEMO_TEXT escaping to use C-style \xNN UTF-8 byte format#140

Merged
christian-rogobete merged 2 commits into
masterfrom
txrep-memo-string
Apr 13, 2026
Merged

Fix SEP-0011 MEMO_TEXT escaping to use C-style \xNN UTF-8 byte format#140
christian-rogobete merged 2 commits into
masterfrom
txrep-memo-string

Conversation

@christian-rogobete

Copy link
Copy Markdown
Member

Summary

Bug fix. The SEP-0011 facade encoded MEMO_TEXT via jsonEncode, producing \uNNNN Unicode escapes for non-ASCII characters. SEP-0011 specifies C-style \xNN UTF-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_TEXT changes byte-for-byte; consumers comparing TxRep strings or using golden files will see diffs. Decoding remains compatible with legacy \uNNNN output from older SDK versions.

Changes

  • lib/src/sep/0011/txrep.dart: _encodeMemo now delegates to TxRepHelper.escapeString. _decodeMemo tries unescapeString first and falls back to jsonDecode only when an unescaped \uNNNN sequence is detected (via lookbehind regex), so legacy TxRep blobs from older SDK versions still parse. Both decode paths wrap FormatException as a TxRep-style Exception.
  • lib/src/xdr/txrep_helper.dart: escapeString now emits \r and \t as C-style short escapes; unescapeString decodes them.
  • Tests: non-ASCII encode, legacy \uNNNN decode, 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 / \t round-trips at the helper level.

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

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.07%. Comparing base (00401bf) to head (67e3edb).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
lib/src/sep/0011/txrep.dart 97.74% <100.00%> (+12.71%) ⬆️
lib/src/xdr/txrep_helper.dart 96.84% <100.00%> (+0.13%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.
@christian-rogobete christian-rogobete merged commit 21edc71 into master Apr 13, 2026
7 checks passed
@christian-rogobete christian-rogobete deleted the txrep-memo-string branch June 14, 2026 21:21
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.

1 participant