Better unicode un-escaping

This commit is contained in:
Gregory Schier
2025-05-16 12:42:08 -07:00
parent 763a60982a
commit 3808215210
2 changed files with 17 additions and 7 deletions

8
package-lock.json generated
View File

@@ -14044,7 +14044,7 @@
"postcss": "^8.4.45",
"postcss-nesting": "^13.0.0",
"tailwindcss": "^3.4.10",
"vite": "6.2.6",
"vite": "6.2.7",
"vite-plugin-static-copy": "^2.2.0",
"vite-plugin-svgr": "^4.3.0",
"vite-plugin-top-level-await": "^1.5.0",
@@ -14584,9 +14584,9 @@
}
},
"src-web/node_modules/vite": {
"version": "6.2.6",
"resolved": "https://registry.npmjs.org/vite/-/vite-6.2.6.tgz",
"integrity": "sha512-9xpjNl3kR4rVDZgPNdTL0/c6ao4km69a/2ihNQbcANz8RuCOK3hQBmLSJf3bRKVQjVMda+YvizNE8AwvogcPbw==",
"version": "6.2.7",
"resolved": "https://registry.npmjs.org/vite/-/vite-6.2.7.tgz",
"integrity": "sha512-qg3LkeuinTrZoJHHF94coSaTfIPyBYoywp+ys4qu20oSJFbKMYoIJo0FWJT9q6Vp49l6z9IsJRbHdcGtiKbGoQ==",
"dev": true,
"license": "MIT",
"dependencies": {

View File

@@ -116,14 +116,16 @@ export function TextViewer({ language, text, responseId, requestId, pretty, clas
body = formattedBody.data;
}
// Decode unicode sequences in the text to readable characters
const decodedBodyText = unescape(body.replace(/\\u/g, '%u')) || body;
// Decode unicode sequences in the text to readable characters
if (pretty) {
body = decodeUnicodeLiterals(body);
}
return (
<Editor
readOnly
className={className}
defaultValue={decodedBodyText}
defaultValue={body}
language={language}
actions={actions}
extraExtensions={extraExtensions}
@@ -132,3 +134,11 @@ export function TextViewer({ language, text, responseId, requestId, pretty, clas
);
}
/** Convert \uXXXX to actual Unicode characters */
function decodeUnicodeLiterals(text: string): string {
const decoded = text.replace(/\\u([0-9a-fA-F]{4})/g, (_, hex) => {
const charCode = parseInt(hex, 16);
return String.fromCharCode(charCode);
});
return decoded;
}