Skip to content

Commit

Permalink
Fix #95 Stop parsing if an escape character precedes nothing
Browse files Browse the repository at this point in the history
Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Oct 20, 2021
1 parent ea397b0 commit 1472d27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
5 changes: 5 additions & 0 deletions src/dockerSemanticTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions test/dockerSemanticTokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 1472d27

Please sign in to comment.