From 37636c72e20811af4d78bdb0c48945e8cf4cc7c6 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 25 Oct 2026 23:45:21 -0500 Subject: [PATCH] fix(json): write the replacement character as raw UTF-8, matching Go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An invalid UTF-8 byte in a string was written as the six-character escape �; Go writes the U+FFFD character as its three UTF-8 bytes (ef bf bd). Measured with Go 1.27.3: json.Marshal(string([]byte{0x8b})) is 22 ef bf bd 22, and a lone surrogate decodes to the same bytes. The byte-quote differential case failed on exactly that difference (input 8b, want 22 ef bf bd 22, got 22 5c 75 66 66 66 64 22). The encoder now takes the raw path for a one-byte U+FFFD. The README sentence that documented the escape is corrected in the same change. Tests: sh tools/test.sh with Go 1.27.3 on PATH, all eleven units PASS (json included), no FAIL lines. Co-Authored-By: Claude Fable 5.1 Co-Authored-By: Drake Stapleton --- om/json/README.md | 4 ++-- om/json/json.om | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/om/json/README.md b/om/json/README.md index 17a8bed..e5f1a19 100644 --- a/om/json/README.md +++ b/om/json/README.md @@ -92,8 +92,8 @@ syntax state: punctuation/field sequencing is the caller's responsibility. canonicalization scheme. Output can exceed the input size and fail explicitly. String output matches Go `json.Marshal(string)`: standard short control escapes, lowercase `\u` -hex, HTML escapes for `<`, `>` and `&`, and escapes for U+2028/U+2029. Invalid UTF-8 becomes -`\ufffd`; a valid U+FFFD scalar remains literal UTF-8, matching Go. Internal helpers all have the +hex, HTML escapes for `<`, `>` and `&`, and escapes for U+2028/U+2029. Invalid UTF-8 becomes the replacement character as raw UTF-8 bytes; a valid +U+FFFD scalar is written the same way, matching Go. Internal helpers all have the `json` prefix; callers should use the APIs above. ## Focused tests diff --git a/om/json/json.om b/om/json/json.om index 9812919..1038cec 100644 --- a/om/json/json.om +++ b/om/json/json.om @@ -650,7 +650,7 @@ p = jsonuesc o p v end else if and eq v 65533 eq get r 1 1 -p = jsonuesc o p v +p = jsonrune o p v else p = jsonrune o p v end