Skip to content

Commit a1e1d1b

Browse files
neuracrcopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 707444715
1 parent 3b3fdac commit a1e1d1b

File tree

7 files changed

+51
-24506
lines changed

7 files changed

+51
-24506
lines changed

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

fixup.sh

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#!/bin/bash
22
# Adds package.json files to cjs/mjs subtrees
33

4-
echo '{
5-
"type": "commonjs"
6-
}' > dist/cjs/package.json
4+
VERSION=$(cat VERSION)
75

8-
echo '{
9-
"type": "module"
10-
}' > dist/mjs/package.json
6+
echo "{
7+
\"type\": \"commonjs\",
8+
\"version\": \"${VERSION}\"
9+
}" > dist/cjs/package.json
10+
11+
echo "{
12+
\"type\": \"module\",
13+
\"version\": \"${VERSION}\"
14+
}" > dist/mjs/package.json
1115

1216
rm -rf dist/mjs/test
1317
mv dist/mjs/src/* dist/mjs

integration_tests/basic_import/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,5 @@
2929
"karma-typescript": "^5.2.0",
3030
"typescript": "^4.1.2",
3131
"karma-typescript-es6-transform": "*"
32-
},
33-
"dependencies": {
34-
"safevalues": "^0.3.1"
3532
}
3633
}

integration_tests/jest/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"@types/jest": "^27.0.0",
2828
"babel-jest": "^27.0.6",
2929
"jest": "^27.0.0",
30-
"safevalues": "^0.3.1",
3130
"ts-jest": "^27.0.0",
3231
"typescript": "^3.9.10"
3332
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "safevalues",
3-
"version": "1.0.0-rc.1",
3+
"version": "1.0.0",
44
"description": "Safe builders for Trusted Types values",
55
"repository": "https://github.com/google/safevalues",
66
"author": "ISE Web Hardening Team",

test/builders/html_sanitizer/html_sanitizer_test.ts

+39-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import {secretToken} from '../../../src/internals/secrets';
8-
import {HTML_TEST_VECTORS} from '../../testing/testvectors/html_test_vectors';
98

109
import {
1110
CssSanitizationFn,
@@ -51,16 +50,46 @@ function sanitizeAssertUnchanged(table: SanitizerTable, html: string): string {
5150
.toString();
5251
}
5352

54-
describe('HtmlSanitizer', () => {
55-
describe('using test vectors', () => {
56-
for (const v of HTML_TEST_VECTORS) {
57-
it(`passes testVector[${v.name}]`, () => {
58-
const sanitized = sanitizeHtml(v.input).toString();
59-
expect(v.acceptable).toContain(sanitized);
60-
});
61-
}
62-
});
53+
describe('sanitizeHtml', () => {
54+
interface TestCase {
55+
html: string;
56+
expected: string;
57+
}
58+
const testCases: TestCase[] = [
59+
{
60+
html: '<a href="javascript:evil()"></a>',
61+
expected: '<a href="about:invalid#zClosurez"></a>',
62+
},
63+
{
64+
html: 'ab<script>alert(1)</script>cd',
65+
expected: 'abcd',
66+
},
67+
{
68+
html: 'ab<style>*{}</style>cd',
69+
expected: 'abcd',
70+
},
71+
{
72+
html: '<iframe src="javascript:evil()"></iframe>',
73+
expected: '',
74+
},
75+
{
76+
html: '<img src=1 onerror=alert(1)>',
77+
expected: '<img src="1" />',
78+
},
79+
{
80+
html: '<select><style></select><script>alert(1)</script>',
81+
expected: '<select></select>',
82+
},
83+
];
84+
for (const testCase of testCases) {
85+
it(`sanitizes ${JSON.stringify(testCase.html)} correctly`, () => {
86+
const sanitized = sanitizeHtml(testCase.html).toString();
87+
expect(sanitized).toEqual(testCase.expected);
88+
});
89+
}
90+
});
6391

92+
describe('HtmlSanitizer', () => {
6493
it('drops unknown elements', () => {
6594
const emptyTable = new SanitizerTable(
6695
new Set(),

0 commit comments

Comments
 (0)