Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 707444715
  • Loading branch information
neuracr authored and copybara-github committed Dec 19, 2024
1 parent 3b3fdac commit a1e1d1b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 24,506 deletions.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
16 changes: 10 additions & 6 deletions fixup.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/bash
# Adds package.json files to cjs/mjs subtrees

echo '{
"type": "commonjs"
}' > dist/cjs/package.json
VERSION=$(cat VERSION)

echo '{
"type": "module"
}' > dist/mjs/package.json
echo "{
\"type\": \"commonjs\",
\"version\": \"${VERSION}\"
}" > dist/cjs/package.json

echo "{
\"type\": \"module\",
\"version\": \"${VERSION}\"
}" > dist/mjs/package.json

rm -rf dist/mjs/test
mv dist/mjs/src/* dist/mjs
Expand Down
3 changes: 0 additions & 3 deletions integration_tests/basic_import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,5 @@
"karma-typescript": "^5.2.0",
"typescript": "^4.1.2",
"karma-typescript-es6-transform": "*"
},
"dependencies": {
"safevalues": "^0.3.1"
}
}
1 change: 0 additions & 1 deletion integration_tests/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@types/jest": "^27.0.0",
"babel-jest": "^27.0.6",
"jest": "^27.0.0",
"safevalues": "^0.3.1",
"ts-jest": "^27.0.0",
"typescript": "^3.9.10"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "safevalues",
"version": "1.0.0-rc.1",
"version": "1.0.0",
"description": "Safe builders for Trusted Types values",
"repository": "https://github.com/google/safevalues",
"author": "ISE Web Hardening Team",
Expand Down
49 changes: 39 additions & 10 deletions test/builders/html_sanitizer/html_sanitizer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

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

import {
CssSanitizationFn,
Expand Down Expand Up @@ -51,16 +50,46 @@ function sanitizeAssertUnchanged(table: SanitizerTable, html: string): string {
.toString();
}

describe('HtmlSanitizer', () => {
describe('using test vectors', () => {
for (const v of HTML_TEST_VECTORS) {
it(`passes testVector[${v.name}]`, () => {
const sanitized = sanitizeHtml(v.input).toString();
expect(v.acceptable).toContain(sanitized);
});
}
});
describe('sanitizeHtml', () => {
interface TestCase {
html: string;
expected: string;
}
const testCases: TestCase[] = [
{
html: '<a href="javascript:evil()"></a>',
expected: '<a href="about:invalid#zClosurez"></a>',
},
{
html: 'ab<script>alert(1)</script>cd',
expected: 'abcd',
},
{
html: 'ab<style>*{}</style>cd',
expected: 'abcd',
},
{
html: '<iframe src="javascript:evil()"></iframe>',
expected: '',
},
{
html: '<img src=1 onerror=alert(1)>',
expected: '<img src="1" />',
},
{
html: '<select><style></select><script>alert(1)</script>',
expected: '<select></select>',
},
];
for (const testCase of testCases) {
it(`sanitizes ${JSON.stringify(testCase.html)} correctly`, () => {
const sanitized = sanitizeHtml(testCase.html).toString();
expect(sanitized).toEqual(testCase.expected);
});
}
});

describe('HtmlSanitizer', () => {
it('drops unknown elements', () => {
const emptyTable = new SanitizerTable(
new Set(),
Expand Down
Loading

0 comments on commit a1e1d1b

Please sign in to comment.