Skip to content

Commit

Permalink
fix(decode): Fix off-by-one error
Browse files Browse the repository at this point in the history
Fixes #852
  • Loading branch information
fb55 committed Jul 1, 2022
1 parent b349edf commit b629e29
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/decode.spec.ts
Expand Up @@ -39,4 +39,7 @@ describe("Decode test", () => {

it("should not parse numeric entities in strict mode", () =>
expect(entities.decodeHTMLStrict("&#55")).toBe("&#55"));

it("should parse &nbsp followed by < (#852)", () =>
expect(entities.decodeHTML("&nbsp<")).toBe("\u00a0<"));
});
2 changes: 1 addition & 1 deletion src/decode.ts
Expand Up @@ -150,7 +150,7 @@ export function determineBranch(
if (jumpOffset) {
const value = char - jumpOffset;

return value < 0 || value > branchCount
return value < 0 || value >= branchCount
? -1
: decodeTree[nodeIdx + value] - 1;
}
Expand Down

0 comments on commit b629e29

Please sign in to comment.