mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-19 07:54:23 +01:00
Better unicode un-escaping
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -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": {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user