@descope-ui/descope-image 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.0.4](https://github.com/descope/web-components-ui/compare/@descope-ui/descope-image-0.0.3...@descope-ui/descope-image-0.0.4) (2025-06-19)
|
|
6
|
+
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `test-assets` updated to version `0.0.1`
|
|
10
|
+
## [0.0.3](https://github.com/descope/web-components-ui/compare/@descope-ui/descope-image-0.0.2...@descope-ui/descope-image-0.0.3) (2025-06-09)
|
|
11
|
+
|
|
12
|
+
### Dependency Updates
|
|
13
|
+
|
|
14
|
+
* `@descope-ui/common` updated to version `0.0.13`
|
|
15
|
+
* `@descope-ui/theme-globals` updated to version `0.0.13`
|
|
5
16
|
## [0.0.2](https://github.com/descope/web-components-ui/compare/@descope-ui/descope-image-0.0.1...@descope-ui/descope-image-0.0.2) (2025-06-03)
|
|
6
17
|
|
|
7
18
|
## 0.0.1 (2025-05-28)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { test, expect } from '@playwright/test';
|
|
2
2
|
import { getStoryUrl, loopConfig, loopPresets } from 'e2e-utils';
|
|
3
|
+
import { Locator } from '@playwright/test';
|
|
3
4
|
|
|
4
5
|
const storyName = 'descope-image';
|
|
5
6
|
const componentName = 'descope-image';
|
|
@@ -45,6 +46,10 @@ test.describe('presets', () => {
|
|
|
45
46
|
'st-width': '200px',
|
|
46
47
|
'st-height': '50px',
|
|
47
48
|
},
|
|
49
|
+
'from url': { src: 'fromUrlLight' },
|
|
50
|
+
svg64: { src: 'base64svg' },
|
|
51
|
+
png64: { src: 'base64png' },
|
|
52
|
+
'sanitized svg': { src: 'base64pngWithForbiddenTags' },
|
|
48
53
|
},
|
|
49
54
|
(preset, name) => {
|
|
50
55
|
test(name, async ({ page }) => {
|
|
@@ -57,3 +62,27 @@ test.describe('presets', () => {
|
|
|
57
62
|
},
|
|
58
63
|
);
|
|
59
64
|
});
|
|
65
|
+
|
|
66
|
+
// Reusable function to check for an SVG with a specific tag inside a node
|
|
67
|
+
async function hasSvgWithTag(component: Locator, tagName: string): Promise<boolean> {
|
|
68
|
+
return await component.evaluate((node, tag) => {
|
|
69
|
+
const svg = node.querySelector('svg');
|
|
70
|
+
if (!svg) return false;
|
|
71
|
+
return svg.querySelector(tag) !== null;
|
|
72
|
+
}, tagName);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
test.describe('sanitation', () => {
|
|
76
|
+
test('sanitize svg', async({ page }) => {
|
|
77
|
+
await page.goto(getStoryUrl(storyName, { src: 'base64pngWithForbiddenTags' }), {
|
|
78
|
+
waitUntil: 'networkidle',
|
|
79
|
+
});
|
|
80
|
+
const component = page.locator(componentName);
|
|
81
|
+
|
|
82
|
+
const hasDefs = await hasSvgWithTag(component, 'defs');
|
|
83
|
+
expect(hasDefs).toBe(false);
|
|
84
|
+
|
|
85
|
+
const hasUse = await hasSvgWithTag(component, 'use');
|
|
86
|
+
expect(hasUse).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope-ui/descope-image",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"import": "./src/component/index.js"
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"dompurify": "^3.1.6",
|
|
22
|
-
"@descope-ui/common": "0.0.
|
|
23
|
-
"@descope-ui/theme-globals": "0.0.
|
|
22
|
+
"@descope-ui/common": "0.0.13",
|
|
23
|
+
"@descope-ui/theme-globals": "0.0.13"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"link-workspace-packages": false
|
package/src/component/helpers.js
CHANGED
|
@@ -20,6 +20,10 @@ const createSvgEle = (text) => {
|
|
|
20
20
|
// we want to purify the SVG to avoid XSS attacks
|
|
21
21
|
const clean = DOMPurify.sanitize(text, {
|
|
22
22
|
USE_PROFILES: { svg: true, svgFilters: true },
|
|
23
|
+
// allow image to render
|
|
24
|
+
ADD_TAGS: ['image'],
|
|
25
|
+
// forbid interactiviy via `use` tags (which are sanitized by default)
|
|
26
|
+
FORBID_TAGS: ['defs']
|
|
23
27
|
});
|
|
24
28
|
|
|
25
29
|
const parser = new DOMParser();
|
|
@@ -7,14 +7,18 @@ import {
|
|
|
7
7
|
|
|
8
8
|
import demoImageLight from './demo.jpg';
|
|
9
9
|
import demoImageDark from './game.png';
|
|
10
|
-
import fromUrlLight from './google.svg
|
|
11
|
-
import fromUrlDark from './apple.svg
|
|
10
|
+
import fromUrlLight from './google.svg';
|
|
11
|
+
import fromUrlDark from './apple.svg';
|
|
12
|
+
import { base64png, base64svg, base64pngWithForbiddenTags } from 'test-assets';
|
|
12
13
|
|
|
13
14
|
const images = {
|
|
14
15
|
fromUrlLight,
|
|
15
16
|
fromUrlDark,
|
|
16
17
|
demoImageLight,
|
|
17
18
|
demoImageDark,
|
|
19
|
+
base64png,
|
|
20
|
+
base64svg,
|
|
21
|
+
base64pngWithForbiddenTags
|
|
18
22
|
};
|
|
19
23
|
|
|
20
24
|
const Template = ({
|