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.
This commit is contained in:
Marc Durdin 2022-11-09 09:43:55 +11:00
parent a4912d4f00
commit 5d41e7a36e

View file

@ -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);
}
};