upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools/rbf0_encode.py
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 17:01:48 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 17:01:48 -0500
commitade14c9fa79a8fc5874ecd8722de59d6ca9384b8 (patch)
treea090ac4a67cc94951741fce32a47153274af97c7 /tools/rbf0_encode.py
parentd51752aa2db5892ae91ea3dae10760512a9e4abd (diff)
parent0264ef1e5f80815217ad99a1ba4f6d03c4d51443 (diff)
Merge pull request #3384 from Shrey Ratna
Diffstat (limited to 'tools/rbf0_encode.py')
-rw-r--r--tools/rbf0_encode.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/rbf0_encode.py b/tools/rbf0_encode.py
index 8c8818612..4a6e1861d 100644
--- a/tools/rbf0_encode.py
+++ b/tools/rbf0_encode.py
@@ -9,7 +9,7 @@ its content in tree order; text and strings with the bytes and terminating NUL t
9The encoder fails closed. When the tree cannot hold the original bytes it raises EncodeError with a short reason 9The encoder fails closed. When the tree cannot hold the original bytes it raises EncodeError with a short reason
10instead of writing something else: 10instead of writing something else:
11 status the parse was not complete (bad, truncated, or bytes after the root closed) 11 status the parse was not complete (bad, truncated, or bytes after the root closed)
12 utf8 a descriptor name, string or text had invalid UTF-8, which the decoder replaced with U+FFFD 12 utf8 a descriptor name, string or text had invalid UTF-8, or an edit contains an unpaired surrogate
13 nan a float or vec3 component was NaN, whose bits the tree renders as text (infinities are exact) 13 nan a float or vec3 component was NaN, whose bits the tree renders as text (infinities are exact)
14 order a value counted as an attribute came after the element's content started 14 order a value counted as an attribute came after the element's content started
15 descriptor a descriptor index outside the table, or a first use out of order 15 descriptor a descriptor index outside the table, or a first use out of order
@@ -184,7 +184,12 @@ def encode(doc):
184 if not isinstance(tree, dict) or tree.get("kind") != "element": 184 if not isinstance(tree, dict) or tree.get("kind") != "element":
185 raise EncodeError("status", "no root element") 185 raise EncodeError("status", "no root element")
186 w = _Writer(doc) 186 w = _Writer(doc)
187 w.element(tree) 187 try:
188 w.element(tree)
189 except UnicodeEncodeError:
190 # JSON accepts escaped lone surrogates, but RBF0 strings must be UTF-8.
191 # Refuse the resource through the same path as invalid decoded UTF-8.
192 raise EncodeError("utf8", "a descriptor name, string or text contains an unpaired Unicode surrogate") from None
188 return bytes(w.out) 193 return bytes(w.out)
189 194
190 195