Skip to content

Commit

Permalink
fix: escape <& characters in attribute values (#1)
Browse files Browse the repository at this point in the history
* fix: escape <& characters in attribute values

* fix: Move & replacement first, so it does not replace the other escaped values
  • Loading branch information
isuda authored Aug 15, 2024
1 parent 8b9aad6 commit 9c626aa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
const path = require('path');

function escapeAttribute(s = '') {
return s.replace(/"/g, '&quot;').replace(/\n/g, '');
return s.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/"/g, '&quot;')
.replace(/\n/g, '');
}

function escapeContent(s = '') {
return s.replace(/</g, '&lt;').replace(/&/g, '&amp;');
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;');
}

function treeToXML(tree) {
Expand Down

0 comments on commit 9c626aa

Please sign in to comment.