Skip to content

Commit adcf2fa

Browse files
authored
Merge pull request #2 from patel-vansh/test/add-new-tests
test: Add test cases for various Svelte components handling unsafe HTML
2 parents 464290e + a0353ce commit adcf2fa

38 files changed

+392
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"filename": "ComplexExpression.svelte",
3+
"parsed": true,
4+
"error": null,
5+
"warnings": [
6+
{
7+
"filename": "ComplexExpression.svelte",
8+
"message": "Unsafe raw HTML insertion without sanitizer",
9+
"start": {
10+
"line": 6,
11+
"column": 11
12+
},
13+
"end": {
14+
"line": 6,
15+
"column": 22
16+
}
17+
},
18+
{
19+
"filename": "ComplexExpression.svelte",
20+
"message": "Unsafe raw HTML insertion without sanitizer",
21+
"start": {
22+
"line": 7,
23+
"column": 11
24+
},
25+
"end": {
26+
"line": 7,
27+
"column": 29
28+
}
29+
},
30+
{
31+
"filename": "ComplexExpression.svelte",
32+
"message": "Unsafe raw HTML insertion without sanitizer",
33+
"start": {
34+
"line": 8,
35+
"column": 11
36+
},
37+
"end": {
38+
"line": 8,
39+
"column": 36
40+
}
41+
}
42+
]
43+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let obj = { content: "<div>Test</div>" };
3+
</script>
4+
5+
<div>
6+
{@html obj.content}
7+
{@html obj.content.trim()}
8+
{@html obj.content.toUpperCase()}
9+
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"filename": "ComplexExpressionWithComment.svelte",
3+
"parsed": true,
4+
"error": null,
5+
"warnings": [
6+
{
7+
"filename": "ComplexExpressionWithComment.svelte",
8+
"message": "Unsafe raw HTML insertion without sanitizer",
9+
"start": {
10+
"line": 10,
11+
"column": 11
12+
},
13+
"end": {
14+
"line": 10,
15+
"column": 36
16+
}
17+
}
18+
]
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
let obj = { content: "<div>Test</div>" };
3+
</script>
4+
5+
<div>
6+
<!-- svelte-ignore unsafe_html -->
7+
{@html obj.content}
8+
<!-- svelte-ignore unsafe_html -->
9+
{@html obj.content.trim()}
10+
{@html obj.content.toUpperCase()}
11+
</div>

tests/fixtures/common/OneUnsafeWithIgnoreComment.expected.json renamed to tests/fixtures/common/Empty.expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"filename": "OneUnsafeWithIgnoreComment.svelte",
2+
"filename": "Empty.svelte",
33
"parsed": true,
44
"error": null,
55
"warnings": []

tests/fixtures/common/Empty.svelte

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"filename": "EmptyWithComment.svelte",
3+
"parsed": true,
4+
"error": null,
5+
"warnings": []
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- This is empty file with comment. -->
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"filename": "InComments.svelte",
3+
"parsed": true,
4+
"error": null,
5+
"warnings": []
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
// {@html commented}
3+
/* {@html blocked} */
4+
let x = 1;
5+
</script>
6+
7+
<!-- {@html inHTMLComment} -->
8+
<div>Normal content</div>

0 commit comments

Comments
 (0)