diff options
author | Thomas Lively <tlively@google.com> | 2024-02-21 12:10:01 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-21 20:10:01 +0000 |
commit | 39ae6cf367fced5aad3224c6bffa086b0cd0d393 (patch) | |
tree | 3a46e5f0ebc3c9d0773d4409f67f5b8e4fed3246 /test | |
parent | a2fa5598104f048bce744db57d4d9407473bcd14 (diff) | |
download | binaryen-39ae6cf367fced5aad3224c6bffa086b0cd0d393.tar.gz binaryen-39ae6cf367fced5aad3224c6bffa086b0cd0d393.tar.bz2 binaryen-39ae6cf367fced5aad3224c6bffa086b0cd0d393.zip |
Improve JSON string encoding (#6328)
Catch and report all kinds of WTF-8 encoding errors in the source strings,
including invalid leading bytes, invalid trailing bytes, unexpected ends of
strings, and invalid surrogate sequences. Insert replacement characters into the
output as necessary. Add a TODO about minimizing size by escaping only those
code points mandated to be escaped by the JSON spec. Generally improve
readability of the code.
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/string-lowering.wast | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/test/lit/passes/string-lowering.wast b/test/lit/passes/string-lowering.wast index 43d30fc64..f7f47871b 100644 --- a/test/lit/passes/string-lowering.wast +++ b/test/lit/passes/string-lowering.wast @@ -14,7 +14,19 @@ (string.const "foo") ) (drop - (string.const "needs\tescaping\00.'#%\"- .\r\n\\.ꙮ") + (string.const "needs\tescaping\00.'#%\"- .\r\n\\08\0C\0A\0D\09.ꙮ") + ) + (drop + (string.const "invalid WTF-8 leading byte \FF") + ) + (drop + (string.const "invalid trailing byte \C0\00") + ) + (drop + (string.const "unexpected end \C0") + ) + (drop + (string.const "invalid surrogate sequence \ED\A0\81\ED\B0\B7") ) ) ) @@ -24,7 +36,7 @@ ;; ;; RUN: wasm-opt %s --string-lowering -all -S -o - | filecheck %s ;; -;; CHECK: custom section "string.consts", size 59, contents: "[\"bar\",\"foo\",\"needs\\tescaping\\u0000.'#%\\\"- .\\r\\n\\\\.\\ua66e\"]" +;; CHECK: custom section "string.consts", size 202, contents: "[\"bar\",\"foo\",\"invalid WTF-8 leading byte \\ufffd\",\"invalid surrogate sequence \\ud801\\udc37\",\"invalid trailing byte \\ufffd\",\"needs\\tescaping\\u0000.'#%\\\"- .\\r\\n\\\\08\\f\\n\\r\\t.\\ua66e\",\"unexpected end \\ufffd\"]" ;; The custom section should parse OK using JSON.parse from node. ;; (Note we run --remove-unused-module-elements to remove externref-using @@ -33,6 +45,5 @@ ;; RUN: wasm-opt %s --string-lowering --remove-unused-module-elements -all -o %t.wasm ;; RUN: node %S/string-lowering.js %t.wasm | filecheck %s --check-prefix=CHECK-JS ;; -;; CHECK-JS: string: ["bar","foo","needs\tescaping\x00.'#%\"- .\r\n\\.\ua66e"] -;; CHECK-JS: JSON: ["bar","foo","needs\tescaping\x00.'#%\"- .\r\n\\.ꙮ"] - +;; CHECK-JS: string: ["bar","foo","invalid WTF-8 leading byte \ufffd","invalid surrogate sequence \ud801\udc37","invalid trailing byte \ufffd","needs\tescaping\x00.'#%\"- .\r\n\\08\f\n\r\t.\ua66e","unexpected end \ufffd"] +;; CHECK-JS: JSON: ["bar","foo","invalid WTF-8 leading byte �","invalid surrogate sequence 𐐷","invalid trailing byte �","needs\tescaping\x00.'#%\"- .\r\n\\08\f\n\r\t.ꙮ","unexpected end �"] |