Skip to content

Commit

Permalink
fix: allow classes that match allowedClasses regex for all tags
Browse files Browse the repository at this point in the history
  • Loading branch information
anak-dev committed Sep 21, 2024
1 parent f47281e commit 7ba71db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,13 @@ function sanitizeHtml(html, options, _recursing) {
const allowedWildcardClasses = allowedClassesMap['*'];
const allowedSpecificClassesGlob = allowedClassesGlobMap[name];
const allowedSpecificClassesRegex = allowedClassesRegexMap[name];
const allowedWildcardClassesRegex = allowedClassesRegexMap['*'];
const allowedWildcardClassesGlob = allowedClassesGlobMap['*'];
const allowedClassesGlobs = [
allowedSpecificClassesGlob,
allowedWildcardClassesGlob
]
.concat(allowedSpecificClassesRegex)
.concat(allowedSpecificClassesRegex, allowedWildcardClassesRegex)
.filter(function (t) {
return t;
});
Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,19 @@ describe('sanitizeHtml', function() {
'<p class="nifty33 dippy">whee</p>'
);
});
it('should allow classes that match `allowedClasses` regex for all tags', function() {
assert.equal(
sanitizeHtml(
'<p class="nifty33 nifty2 dippy">whee</p>',
{
allowedClasses: {
'*': [ /^nifty\d{2}$/, /^d\w{4}$/ ]
}
}
),
'<p class="nifty33 dippy">whee</p>'
);
});
it('should allow defining schemes on a per-tag basis', function() {
assert.equal(
sanitizeHtml(
Expand Down

0 comments on commit 7ba71db

Please sign in to comment.