Skip to content

Commit

Permalink
fix breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprudhomme committed Nov 26, 2024
1 parent 6bacb23 commit 1a8d478
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 19 deletions.
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/atomic/cypress/e2e/icon-assertions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {sanitize} from 'dompurify';
import DOMPurify from 'dompurify';
import {getSvg} from './icon-utils';

function getSortedClone(element: Element) {
Expand All @@ -22,7 +22,7 @@ export function assertRendersIcon(
selector().should(([actualSvgElement]) =>
expect(getSortedClone(actualSvgElement).outerHTML).to.eq(
getSortedClone(
sanitize(expectedSvg, {
DOMPurify.sanitize(expectedSvg, {
USE_PROFILES: {svg: true, svgFilters: true},
RETURN_DOM_FRAGMENT: true,
}).querySelector('svg')!
Expand Down
1 change: 0 additions & 1 deletion packages/atomic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
"@swc/core": "~1.7.0",
"@swc/helpers": "~0.5.2",
"@types/core-js": "2.5.8",
"@types/dompurify": "3.0.5",
"@types/escape-html": "1.0.4",
"@types/jest": "29.5.12",
"@types/lodash": "4.17.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
State,
Watch,
} from '@stencil/core';
import {sanitize} from 'dompurify';
import DOMPurify from 'dompurify';
import {
InitializableComponent,
InitializeBindings,
Expand Down Expand Up @@ -102,7 +102,7 @@ export class AtomicIcon implements InitializableComponent<AnyBindings> {
this.validateSVG(svg);
}
const sanitizedSvg = svg
? sanitize(svg, {
? DOMPurify.sanitize(svg, {
USE_PROFILES: {svg: true, svgFilters: true},
})
: null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Host,
Element,
} from '@stencil/core';
import {sanitize} from 'dompurify';
import DOMPurify from 'dompurify';
import {sanitizeStyle} from '../../../../utils/utils';
import {bindAnalyticsToLink} from '../../item-link/item-link';

Expand Down Expand Up @@ -125,7 +125,7 @@ export class AtomicSmartSnippetAnswer {
>
{/* deepcode ignore ReactSetInnerHtml: Sanitized by back-end + dompurify */}
<div
innerHTML={sanitize(this.htmlContent, {
innerHTML={DOMPurify.sanitize(this.htmlContent, {
USE_PROFILES: {html: true},
})}
ref={(element) => element && this.bindAnalyticsToLinks(element)}
Expand Down
4 changes: 2 additions & 2 deletions packages/atomic/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {getAssetPath} from '@stencil/core';
import {NODE_TYPES} from '@stencil/core/mock-doc';
import {sanitize} from 'dompurify';
import DOMPurify from 'dompurify';

/**
* Returns a function that can be executed only once
Expand Down Expand Up @@ -149,7 +149,7 @@ export const sortByDocumentPosition = (a: Node, b: Node): 1 | -1 =>
a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;

export function sanitizeStyle(style: string) {
const purifiedOuterHTML = sanitize(`<style>${style}</style>`, {
const purifiedOuterHTML = DOMPurify.sanitize(`<style>${style}</style>`, {
ALLOWED_TAGS: ['style'],
ALLOWED_ATTR: [],
FORCE_BODY: true,
Expand Down

0 comments on commit 1a8d478

Please sign in to comment.