Skip to content

Commit

Permalink
refactor: don't poll xmlnsOpt in each iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
lddubeau committed Aug 24, 2018
1 parent c8b7ae2 commit 1981d7d
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,14 +968,26 @@ class SaxesParser {
let check = this.piTarget.length === 0 ? isNameStartChar : isNameChar;
const c = this.captureWhile(
chunkState,
// When namespaces are used, colons are not allowed in pi targets
// names.
// https://www.w3.org/XML/xml-names-19990114-errata.html
// NE08
this.xmlnsOpt ?
(cx) => {
if (cx !== QUESTION && !isS(cx)) {
if (!(check(cx) &&
// When namespaces are used, colons are not allowed in entity
// names.
// https://www.w3.org/XML/xml-names-19990114-errata.html
// NE08
(!this.xmlnsOpt || cx !== COLON))) {
if (!(check(cx) && cx !== COLON)) {
this.fail("disallowed characer in processing instruction name.");
}

check = isNameChar;
return true;
}

return false;
} :
(cx) => {
if (cx !== QUESTION && !isS(cx)) {
if (!check(cx)) {
this.fail("disallowed characer in processing instruction name.");
}

Expand Down Expand Up @@ -1464,13 +1476,20 @@ class SaxesParser {
sEntity(chunkState) {
let check = this.entity.length === 0 ? isEntityStartChar : isNameChar;
const c = this.captureWhile(chunkState,
// When namespaces are used, colons are
// not valid in entity names.
// https://www.w3.org/XML/xml-names-19990114-errata.html
// NE08
this.xmlnsOpt ?
(cx) => {
if (check(cx) &&
// When namespaces are used, colons are
// not valid in entity names.
// https://www.w3.org/XML/xml-names-19990114-errata.html
// NE08
(!this.xmlnsOpt || cx !== COLON)) {
if (check(cx) && cx !== COLON) {
check = isNameChar;
return true;
}

return false;
} : (cx) => {
if (check(cx)) {
check = isNameChar;
return true;
}
Expand Down

0 comments on commit 1981d7d

Please sign in to comment.