From 5d41e7a36ee4e082fe71182e9f5ff19d7f484160 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Wed, 9 Nov 2022 09:43:55 +1100 Subject: [PATCH] fix(developer): handle unpaired surrogate Fixes #7658. When manipulating text that contains an unpaired surrogate, the text editor could throw an exception trying to encode the text to send through to the token command. This simply masks that error. --- developer/src/tike/xml/app/editor/editor.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/developer/src/tike/xml/app/editor/editor.js b/developer/src/tike/xml/app/editor/editor.js index 0ba17a05a9..2e5750e4c2 100644 --- a/developer/src/tike/xml/app/editor/editor.js +++ b/developer/src/tike/xml/app/editor/editor.js @@ -426,7 +426,19 @@ async function loadSettings() { command('location,' + (s.startLineNumber-1) + ',' + (s.startColumn-1) + ',' + (s.endLineNumber-1) + ',' + (s.endColumn-1) + ',' + n); var token = getTokenAtCursor(); if (token) { - command('token,' + token.column + ',' + encodeURIComponent(token.text)); + let text; + try { + text = encodeURIComponent(token.text); + } catch(e) { + if(e instanceof URIError) { + // if token.text contains an unpaired surrogate, encodeURIComponent + // fails with a URIError, in which case we will just avoid + // sending the token command. + return; + } + throw e; + } + command('token,' + token.column + ',' + text); } };