Skip to content

Commit db73dd7

Browse files
authoredDec 6, 2023
Merge pull request #885 from cure53/main
Update 3.x to be in sync with main
2 parents 1b864e7 + c29aa90 commit db73dd7

17 files changed

+944
-1384
lines changed
 

‎.github/workflows/build-and-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Checkout
2424
uses: actions/checkout@v4
2525
- name: Setup Node.js ${{ matrix.node-version }}
26-
uses: actions/setup-node@v3
26+
uses: actions/setup-node@v4
2727
with:
2828
node-version: ${{ matrix.node-version }}
2929
cache: 'npm'

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const clean = DOMPurify.sanitize(dirty, {ALLOW_UNKNOWN_PROTOCOLS: true});
271271
// allow specific protocols handlers in URL attributes via regex (default is false, be careful, XSS risk)
272272
// by default only http, https, ftp, ftps, tel, mailto, callto, sms, cid and xmpp are allowed.
273273
// Default RegExp: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
274-
const clean = DOMPurify.sanitize(dirty, {ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|xxx):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;});
274+
const clean = DOMPurify.sanitize(dirty, {ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|xxx):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i});
275275

276276
```
277277
### Influence the return-type

‎demos/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ var config = {
286286
};
287287

288288
// Specify attributes to proxy
289-
var attributes = ['action', 'background', 'href', 'poster', 'src'];
289+
var attributes = ['action', 'background', 'href', 'poster', 'src', 'srcset']
290290

291291
// specify the regex to detect external content
292292
var regex = /(url\("?)(?!data:)/gim;

‎dist/purify.cjs.js

+197-381
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.cjs.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.es.js.map

-1
This file was deleted.

‎dist/purify.es.js ‎dist/purify.es.mjs

+198-382
Large diffs are not rendered by default.

‎dist/purify.es.mjs.map

+1
Large diffs are not rendered by default.

‎dist/purify.js

+197-381
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package-lock.json

+277-198
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+16-8
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,27 @@
77
"commit-amend-build": "scripts/commit-amend-build.sh",
88
"prebuild": "rimraf dist/**",
99
"dev": "cross-env NODE_ENV=development BABEL_ENV=rollup rollup -w -c -o dist/purify.js",
10-
"build": "cross-env run-p build:umd build:umd:min build:es build:cjs",
11-
"build:umd": "cross-env NODE_ENV=development BABEL_ENV=rollup rollup -c -f umd -o dist/purify.js",
12-
"build:umd:min": "cross-env NODE_ENV=production BABEL_ENV=rollup rollup -c -f umd -o dist/purify.min.js",
13-
"build:es": "cross-env NODE_ENV=development BABEL_ENV=rollup rollup -c -f es -o dist/purify.es.js",
14-
"build:cjs": "cross-env NODE_ENV=development BABEL_ENV=rollup rollup -c -f cjs -o dist/purify.cjs.js",
10+
"build": "rollup -c",
11+
"build:umd": "rollup -c -f umd -o dist/purify.js",
12+
"build:umd:min": "rollup -c -f umd -o dist/purify.min.js -p terser",
13+
"build:es": "rollup -c -f es -o dist/purify.es.mjs",
14+
"build:cjs": "rollup -c -f cjs -o dist/purify.cjs.js",
1515
"test:jsdom": "cross-env NODE_ENV=test BABEL_ENV=rollup node test/jsdom-node-runner --dot",
1616
"test:karma": "cross-env NODE_ENV=test BABEL_ENV=rollup karma start test/karma.conf.js --log-level warn ",
1717
"test:ci": "cross-env NODE_ENV=test BABEL_ENV=rollup npm run test:jsdom && npm run test:karma -- --log-level error --reporters dots --single-run --shouldTestOnBrowserStack=\"${TEST_BROWSERSTACK}\" --shouldProbeOnly=\"${TEST_PROBE_ONLY}\"",
1818
"test": "cross-env NODE_ENV=test BABEL_ENV=rollup npm run lint && npm run test:jsdom && npm run test:karma -- --browsers Chrome"
1919
},
20-
"main": "dist/purify.cjs.js",
21-
"module": "dist/purify.es.js",
22-
"browser": "dist/purify.js",
20+
"exports": {
21+
".": {
22+
"require": "./dist/purify.cjs.js",
23+
"import": "./dist/purify.es.mjs"
24+
},
25+
"./package.json": "./package.json"
26+
},
27+
"main": "./dist/purify.cjs.js",
28+
"module": "./dist/purify.es.mjs",
29+
"browser": "./dist/purify.js",
30+
"production": "./dist/purify.min.js",
2331
"files": [
2432
"dist"
2533
],

‎rollup.config.js

+36-14
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,48 @@ const babel = require('@rollup/plugin-babel').babel;
33
const nodeResolve = require('@rollup/plugin-node-resolve').nodeResolve;
44
const replace = require('@rollup/plugin-replace');
55
const { terser } = require('rollup-plugin-terser');
6+
const pkg = require('./package.json');
67

78
const env = process.env.NODE_ENV;
8-
const isProd = env === 'production';
9+
const event = process.env.npm_lifecycle_event; // build, build:umd, ...
910
const version = process.env.npm_package_version;
10-
const license = fs.readFileSync('./src/license_header', 'utf8').replace(/VERSION/ig, version);
11+
const license = fs
12+
.readFileSync('./src/license_header', 'utf8')
13+
.replace(/VERSION/gi, version);
14+
15+
const commonOutputConfig = {
16+
name: 'DOMPurify',
17+
sourcemap: true,
18+
banner: license,
19+
exports: 'default',
20+
};
1121

1222
const config = {
1323
input: 'src/purify.js',
1424
external: [],
15-
output: {
16-
name: 'DOMPurify',
17-
globals: {},
18-
format: 'umd',
19-
sourcemap: true,
20-
banner: license,
21-
},
25+
output: [
26+
{
27+
...commonOutputConfig,
28+
file: pkg.browser,
29+
format: 'umd',
30+
},
31+
{
32+
...commonOutputConfig,
33+
file: pkg.production,
34+
format: 'umd',
35+
plugins: event === 'build' ? [terser()] : [],
36+
},
37+
{
38+
...commonOutputConfig,
39+
file: pkg.module,
40+
format: 'es',
41+
},
42+
{
43+
...commonOutputConfig,
44+
file: pkg.main,
45+
format: 'cjs',
46+
},
47+
],
2248
plugins: [
2349
babel({
2450
// It is recommended to configure this option explicitly (even if with its default value) so an informed decision is taken on how those babel helpers are inserted into the code.
@@ -32,13 +58,9 @@ const config = {
3258
values: {
3359
'process.env.NODE_ENV': JSON.stringify(env),
3460
VERSION: `'${version}'`,
35-
}
61+
},
3662
}),
3763
],
3864
};
3965

40-
if (isProd) {
41-
config.plugins.push(terser());
42-
}
43-
4466
module.exports = config;

‎scripts/commit-amend-build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
echo "# Amending minified assets to HEAD"
22

3-
git add ./dist/purify.js ./dist/purify.js.map ./dist/purify.min.js ./dist/purify.min.js.map ./dist/purify.cjs.js ./dist/purify.cjs.js.map ./dist/purify.es.js ./dist/purify.es.js.map
3+
git add ./dist/purify.js ./dist/purify.js.map ./dist/purify.min.js ./dist/purify.min.js.map ./dist/purify.cjs.js ./dist/purify.cjs.js.map ./dist/purify.es.mjs ./dist/purify.es.mjs.map

‎src/purify.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const getGlobal = function () {
2828
/**
2929
* Creates a no-op policy for internal use only.
3030
* Don't export this function outside this module!
31-
* @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.
31+
* @param {TrustedTypePolicyFactory} trustedTypes The policy factory.
3232
* @param {HTMLScriptElement} purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
33-
* @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types
33+
* @return {TrustedTypePolicy} The policy created (or null, if Trusted Types
3434
* are not supported or creating the policy failed).
3535
*/
3636
const _createTrustedTypesPolicy = function (trustedTypes, purifyHostElement) {
@@ -412,8 +412,8 @@ function createDOMPurify(window = getGlobal()) {
412412
PARSER_MEDIA_TYPE =
413413
// eslint-disable-next-line unicorn/prefer-includes
414414
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1
415-
? (PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE)
416-
: (PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE);
415+
? DEFAULT_PARSER_MEDIA_TYPE
416+
: cfg.PARSER_MEDIA_TYPE;
417417

418418
// HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
419419
transformCaseFunc =
@@ -515,7 +515,7 @@ function createDOMPurify(window = getGlobal()) {
515515

516516
/* Parse profile info */
517517
if (USE_PROFILES) {
518-
ALLOWED_TAGS = addToSet({}, [...TAGS.text]);
518+
ALLOWED_TAGS = addToSet({}, TAGS.text);
519519
ALLOWED_ATTR = [];
520520
if (USE_PROFILES.html === true) {
521521
addToSet(ALLOWED_TAGS, TAGS.html);
@@ -658,12 +658,15 @@ function createDOMPurify(window = getGlobal()) {
658658
/* Keep track of all possible SVG and MathML tags
659659
* so that we can perform the namespace checks
660660
* correctly. */
661-
const ALL_SVG_TAGS = addToSet({}, TAGS.svg);
662-
addToSet(ALL_SVG_TAGS, TAGS.svgFilters);
663-
addToSet(ALL_SVG_TAGS, TAGS.svgDisallowed);
664-
665-
const ALL_MATHML_TAGS = addToSet({}, TAGS.mathMl);
666-
addToSet(ALL_MATHML_TAGS, TAGS.mathMlDisallowed);
661+
const ALL_SVG_TAGS = addToSet({}, [
662+
...TAGS.svg,
663+
...TAGS.svgFilters,
664+
...TAGS.svgDisallowed,
665+
]);
666+
const ALL_MATHML_TAGS = addToSet({}, [
667+
...TAGS.mathMl,
668+
...TAGS.mathMlDisallowed,
669+
]);
667670

668671
/**
669672
* @param {Element} element a DOM element whose namespace is being checked

0 commit comments

Comments
 (0)
Please sign in to comment.