Skip to content

Commit

Permalink
refactor(dom): Use const values
Browse files Browse the repository at this point in the history
  • Loading branch information
karfau committed Jan 21, 2021
1 parent 169738a commit 0ce0c65
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/dom.js
Expand Up @@ -402,12 +402,17 @@ Node.prototype = {
}
};

const AMP = '&';
const GT = '>';
const LT = '<';
const CDATA_END_ESCAPED = ']]'+GT;
const QUOT = '"';

function _xmlEncoder(c){
return c == '<' && '&lt;' ||
c == '>' && '&gt;' ||
c == '&' && '&amp;' ||
c == '"' && '&quot;' ||
return c == '<' && LT ||
c == '>' && GT ||
c == '&' && AMP ||
c == '"' && QUOT ||
'&#'+c.charCodeAt()+';'
}

Expand Down Expand Up @@ -1083,7 +1088,7 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
*/
return buf.push(node.data
.replace(/[<&]/g,_xmlEncoder)
.replace(/]]>/g, ']]&gt;')
.replace(/]]>/g, CDATA_END_ESCAPED)
);
case CDATA_SECTION_NODE:
return buf.push( '<![CDATA[',node.data,']]>');
Expand Down

0 comments on commit 0ce0c65

Please sign in to comment.