Skip to content

Commit

Permalink
fix: verify that character references match the CHAR production
Browse files Browse the repository at this point in the history
  • Loading branch information
lddubeau committed Jul 5, 2018
1 parent 2c939fe commit 369afde
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { XML_1_0: { ED5 } } = require("xmlchars");

const {
regexes: {
CHAR,
NAME_START_CHAR,
NAME_CHAR,
},
Expand Down Expand Up @@ -1091,7 +1092,14 @@ ${XML_NAMESPACE}.`);
return `&${this.entity};`;
}

return String.fromCodePoint(num);
const char = String.fromCodePoint(num);
// The character reference is required to match the CHAR production.
if (!CHAR.test(char)) {
this.fail("Invalid character entity");
return `&${this.entity};`;
}

return char;
}
}

Expand Down

0 comments on commit 369afde

Please sign in to comment.