Skip to content

Commit c7b6c7d

Browse files
authored
test(sanitization): migrate test to spec (#19186)
1 parent f2cfdf1 commit c7b6c7d

File tree

6 files changed

+47
-143
lines changed

6 files changed

+47
-143
lines changed

core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"tslib": "^1.10.0"
3535
},
3636
"devDependencies": {
37-
"@stencil/core": "1.2.5",
37+
"@stencil/core": "1.3.1",
3838
"@stencil/sass": "1.0.1",
3939
"@types/jest": "24.0.17",
4040
"@types/node": "12.7.1",

core/src/components/router/router.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class Router implements ComponentInterface {
104104
* Go back to previous page in the window.history.
105105
*/
106106
@Method()
107-
back() {
107+
back(): Promise<void> {
108108
window.history.back();
109109
return Promise.resolve(this.waitPromise);
110110
}

core/src/utils/sanitization/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const sanitizeElement = (element: any) => {
8484
if (element.nodeType && element.nodeType !== 1) { return; }
8585

8686
for (let i = element.attributes.length - 1; i >= 0; i--) {
87-
const attribute = element.attributes[i];
87+
const attribute = element.attributes.item(i);
8888
const attributeName = attribute.name;
8989

9090
// remove non-allowed attribs

core/src/utils/sanitization/test/e2e.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

core/src/utils/sanitization/test/index.html

Lines changed: 0 additions & 114 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { sanitizeDOMString } from "..";
2+
3+
describe('sanitizeDOMString', () => {
4+
5+
it('filter onerror', () => {
6+
expect(sanitizeDOMString('<img src="x" onerror="alert(document.cookie);">'))
7+
.toEqual('<img src="x">');
8+
});
9+
10+
it('filter onclick', () => {
11+
expect(sanitizeDOMString('<button id="myButton" name="myButton" onclick="alert(document.cookie);">harmless button</button>'))
12+
.toEqual('<button id="myButton" name="myButton">harmless button</button>');
13+
});
14+
15+
it('filter <a> href JS', () => {
16+
expect(sanitizeDOMString('<a href="javascript:alert(document.cookie)">harmless link</a>'))
17+
.toEqual('<a>harmless link</a>');
18+
});
19+
20+
it('filter <a> href JS + class attribute', () => {
21+
expect(sanitizeDOMString('<a class="link" href="Javascript&#58;alert(document.cookie)">harmless link</a>'))
22+
.toEqual('<a class="link">harmless link</a>');
23+
});
24+
25+
it('filter <iframe>', () => {
26+
expect(sanitizeDOMString('<iframe src="javascript:alert(document.cookie)"></iframe>'))
27+
.toEqual('');
28+
});
29+
30+
it('filter href + javascript ', () => {
31+
expect(sanitizeDOMString('<div><button><a href="javascript:alert(document.cookie)">click me</a></button></div>'))
32+
.toEqual('<div><button><a>click me</a></button></div>');
33+
});
34+
35+
it('filter <object>', () => {
36+
expect(sanitizeDOMString('<object><img src="x" onerror="alert(document.cookie);"></object>'))
37+
.toEqual('');
38+
});
39+
40+
it('sanitizeDOMString', () => {
41+
expect(sanitizeDOMString('<ion-item><ion-label>Hello!</ion-label><ion-button onclick="alert(document.cookie);">Click me</ion-button>'))
42+
.toEqual('<ion-item><ion-label>Hello!</ion-label><ion-button>Click me</ion-button></ion-item>');
43+
});
44+
});

0 commit comments

Comments
 (0)