Skip to content

Commit c5dbdf7

Browse files
authored
Merge pull request #650 from dylanarmstrong/fix/ignore-source-maps
fix: ignore source maps when processing with postcss
2 parents 5a5a74e + 1e2294c commit c5dbdf7

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
- Clarified the use of SVGs with a new test and changes to documentation. Thanks to [Gauav Kumar](https://github.com/gkumar9891) for the contribution.
88

9+
- Do not process source maps when processing style tags with PostCSS.
10+
911
## 2.11.0 (2023-06-21)
1012

1113
- Fix to allow `false` in `allowedClasses` attributes. Thanks to [Kevin Jiang](https://github.com/KevinSJ) for this fix!

Diff for: index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ function sanitizeHtml(html, options, _recursing) {
453453
if (a === 'style') {
454454
if (options.parseStyleAttributes) {
455455
try {
456-
const abstractSyntaxTree = postcssParse(name + ' {' + value + '}');
456+
const abstractSyntaxTree = postcssParse(name + ' {' + value + '}', { map: false });
457457
const filteredAST = filterCss(abstractSyntaxTree, options.allowedStyles);
458458

459459
value = stringifyStyleAttributes(filteredAST);

Diff for: test/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -1659,5 +1659,13 @@ describe('sanitizeHtml', function() {
16591659
}
16601660
}), '<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><linearGradient id="myGradient" gradientTransform="rotate(90)"><stop offset="5%" stop-color="gold"></stop><stop offset="95%" stop-color="red"></stop></linearGradient></defs><circle cx="5" cy="5" r="4" fill="url(\'#myGradient\')"></circle></svg>');
16611661
});
1662+
it('should not process style sourceMappingURL with postCSS', () => {
1663+
assert.equal(sanitizeHtml('<a style=\'background-image: url("/*# sourceMappingURL=../index.js */");\'></a>', {
1664+
allowedAttributes: {
1665+
...sanitizeHtml.defaults.allowedAttributes,
1666+
a: [ 'style' ]
1667+
}
1668+
}), '<a style="background-image:url(&quot;/*# sourceMappingURL=../index.js */&quot;)"></a>');
1669+
});
16621670

16631671
});

0 commit comments

Comments
 (0)