Skip to content

Commit f25b03d

Browse files
committed
Fix XML sanitization lint violations
1 parent aa003c9 commit f25b03d

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/blog-post-workflow.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,17 @@ const sanitizeXml = (xmlText) =>
130130
xmlText
131131
.replace(/^\uFEFF/, '')
132132
.replace(/^[^<]*/, '')
133-
.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, '')
134-
.replace(
135-
/&(?!(?:amp|lt|gt|quot|apos|#\d+|#x[\dA-Fa-f]+);)/g,
136-
'&amp;',
137-
);
133+
.split('')
134+
.filter((char) => {
135+
const charCode = char.charCodeAt(0);
136+
// XML 1.0 valid control chars: tab(9), LF(10), CR(13)
137+
if (charCode <= 31 || charCode === 127) {
138+
return charCode === 9 || charCode === 10 || charCode === 13;
139+
}
140+
return true;
141+
})
142+
.join('')
143+
.replace(/&(?!(?:amp|lt|gt|quot|apos|#\d+|#x[\dA-Fa-f]+);)/g, '&amp;');
138144

139145
const parseFeed = async (siteUrl) => {
140146
try {

0 commit comments

Comments
 (0)