diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b82985..f48e00f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [Unreleased] +### Fixed +- prevent infinite loop when calculating semantic tokens if an escape character is not followed by any actual content ([#95](https://github.com/rcjsuen/dockerfile-language-service/issues/95)) + ## [0.7.2] - 2021-09-21 ### Fixed - prevent infinite loop when calculating semantic tokens for an instruction with a keyword that spans multiple lines ([#94](https://github.com/rcjsuen/dockerfile-language-service/issues/94)) diff --git a/src/dockerSemanticTokens.ts b/src/dockerSemanticTokens.ts index 1999003..fd065d7 100644 --- a/src/dockerSemanticTokens.ts +++ b/src/dockerSemanticTokens.ts @@ -501,6 +501,11 @@ export class DockerSemanticTokens { break; } } + + if (startOffset === -1) { + // we've processed the intermediate token but there is nothing of interest after it + return; + } const intermediateRange = { start: this.document.positionAt(startOffset), end: this.document.positionAt(endOffset), diff --git a/test/dockerSemanticTokens.test.ts b/test/dockerSemanticTokens.test.ts index d70f976..343bd53 100644 --- a/test/dockerSemanticTokens.test.ts +++ b/test/dockerSemanticTokens.test.ts @@ -1234,6 +1234,13 @@ describe("Dockerfile Semantic Token tests", () => { assertEdit(tokens.data, SemanticTokenTypes.keyword, 10, 1, 0, 1); assertEdit(tokens.data, SemanticTokenTypes.keyword, 15, 1, 0, 3); }); + + it("splits into nothing", () => { + const tokens = computeSemanticTokens("R\\ \n"); + assert.strictEqual(10, tokens.data.length); + assertEdit(tokens.data, SemanticTokenTypes.keyword, 0, 0, 0, 1); + assertEdit(tokens.data, SemanticTokenTypes.macro, 5, 0, 1, 1); + }); }); describe("split arguments", () => {