From cee651c21074cfa60495c4cd75cef1f86d90664a Mon Sep 17 00:00:00 2001 From: Oleg Solomko Date: Mon, 31 Mar 2025 11:28:35 -0700 Subject: [PATCH] fix javascript string indexing in the simple decoder logic --- .../editor/common/codecs/simpleCodec/simpleDecoder.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/vs/editor/common/codecs/simpleCodec/simpleDecoder.ts b/src/vs/editor/common/codecs/simpleCodec/simpleDecoder.ts index 205fcfb191a..e9d97747c3c 100644 --- a/src/vs/editor/common/codecs/simpleCodec/simpleDecoder.ts +++ b/src/vs/editor/common/codecs/simpleCodec/simpleDecoder.ts @@ -92,16 +92,16 @@ export class SimpleDecoder extends BaseDecoder } // loop through the text separating it into `Word` and `well-known` tokens + const lineText = line.text.split(''); let i = 0; - while (i < line.text.length) { + while (i < lineText.length) { // index is 0-based, but column numbers are 1-based const columnNumber = i + 1; // check if the current character is a well-known token const tokenConstructor = WELL_KNOWN_TOKENS .find((wellKnownToken) => { - // TODO: @legomushroom - indexing inside the string is incorrect - return wellKnownToken.symbol === line.text[i]; + return wellKnownToken.symbol === lineText[i]; }); // if it is a well-known token, emit it and continue to the next one @@ -116,9 +116,8 @@ export class SimpleDecoder extends BaseDecoder // that needs to be collected into a single `Word` token, hence // read all the characters until a stop character is encountered let word = ''; - while (i < line.text.length && !(WORD_STOP_CHARACTERS.includes(line.text[i]))) { - // TODO: @legomushroom - indexing inside the string is incorrect - word += line.text[i]; + while (i < lineText.length && !(WORD_STOP_CHARACTERS.includes(lineText[i]))) { + word += lineText[i]; i++; }