html-minifier-next 6.2.2 → 6.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2103,7 +2103,7 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
2103
2103
  // Imports
2104
2104
 
2105
2105
 
2106
- // Lazy-load entities only when `decodeEntities` is enabled
2106
+ // Lazy-load entities (used for `decodeEntities` and event-handler attribute decode before `minifyJS`)
2107
2107
 
2108
2108
  let decodeHTMLStrictPromise;
2109
2109
  async function getDecodeHTMLStrict() {
@@ -2399,6 +2399,23 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs, minifyHTM
2399
2399
 
2400
2400
  if (isEventAttr) {
2401
2401
  attrValue = trimWhitespace(attrValue).replace(/^javascript:\s*/i, '');
2402
+ // Browsers decode attribute values before running event-handler JS—
2403
+ // decode first so the minifier gets valid JavaScript
2404
+ if (!options.decodeEntities && options.minifyJS !== identity && attrValue.indexOf('&') !== -1) {
2405
+ return getDecodeHTMLStrict().then(decode => {
2406
+ const decoded = decode(attrValue);
2407
+ const result = options.minifyJS(decoded, true);
2408
+ const reEncode = v => (v && v.indexOf('&') !== -1) ? v.replace(RE_AMP_ENTITY, '&$1') : v;
2409
+ if (isThenable(result)) {
2410
+ return result.then(reEncode, err => {
2411
+ if (!options.continueOnMinifyError) throw err;
2412
+ options.log && options.log(err);
2413
+ return attrValue;
2414
+ });
2415
+ }
2416
+ return reEncode(result);
2417
+ });
2418
+ }
2402
2419
  const result = options.minifyJS(attrValue, true);
2403
2420
  if (isThenable(result)) {
2404
2421
  return result.catch(err => {
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../src/lib/attributes.js"],"names":[],"mappings":"AAmCA,mEAOC;AAED,uEAWC;AAED,8DAGC;AAED,4EAOC;AAgCD,mGAuCC;AAED,mEAGC;AAED,qEAGC;AAED,kEAWC;AAED,sEAGC;AAED,8DAWC;AAED,2EAIC;AAmBD,qEAGC;AAgBD,wEAGC;AAED,sEAUC;AAED,2EAEC;AAED,2DAEC;AAED,8DAUC;AAED,uEAUC;AAED,oGASC;AAED,4DAOC;AAUD,iIA4KC;AAwBD,mGAYC;AA0CD,6GAuHC;AAxlBD;;;;;;;GAOG;AACH,mEAHW,OAAO,SAuBjB"}
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../src/lib/attributes.js"],"names":[],"mappings":"AAmCA,mEAOC;AAED,uEAWC;AAED,8DAGC;AAED,4EAOC;AAgCD,mGAuCC;AAED,mEAGC;AAED,qEAGC;AAED,kEAWC;AAED,sEAGC;AAED,8DAWC;AAED,2EAIC;AAmBD,qEAGC;AAgBD,wEAGC;AAED,sEAUC;AAED,2EAEC;AAED,2DAEC;AAED,8DAUC;AAED,uEAUC;AAED,oGASC;AAED,4DAOC;AAUD,iIA6LC;AAwBD,mGAYC;AA0CD,6GAuHC;AAzmBD;;;;;;;GAOG;AACH,mEAHW,OAAO,SAuBjB"}
package/package.json CHANGED
@@ -5,25 +5,25 @@
5
5
  },
6
6
  "bugs": "https://github.com/j9t/html-minifier-next/issues",
7
7
  "dependencies": {
8
- "commander": "^14.0.2",
8
+ "commander": "^14.0.3",
9
9
  "entities": "^8.0.0",
10
10
  "lightningcss": "^1.32.0",
11
11
  "svgo": "^4.0.1",
12
- "terser": "^5.46.1"
12
+ "terser": "^5.46.2"
13
13
  },
14
14
  "description": "Super-configurable and well-tested web page minifier (enhanced successor of HTML Minifier)",
15
15
  "devDependencies": {
16
- "@commitlint/cli": "^20.5.0",
16
+ "@commitlint/cli": "^20.5.3",
17
17
  "@eslint/js": "^10.0.1",
18
18
  "@rollup/plugin-commonjs": "^29.0.2",
19
19
  "@rollup/plugin-json": "^6.1.0",
20
20
  "@rollup/plugin-node-resolve": "^16.0.3",
21
- "@swc/core": "^1.15.30",
22
- "eslint": "^10.2.0",
21
+ "@swc/core": "^1.15.32",
22
+ "eslint": "^10.3.0",
23
23
  "rollup": "^4.60.2",
24
24
  "rollup-plugin-polyfill-node": "^0.13.0",
25
25
  "typescript": "^6.0.3",
26
- "vite": "^8.0.8"
26
+ "vite": "^8.0.10"
27
27
  },
28
28
  "exports": {
29
29
  ".": {
@@ -96,5 +96,5 @@
96
96
  },
97
97
  "type": "module",
98
98
  "types": "./dist/types/htmlminifier.d.ts",
99
- "version": "6.2.2"
99
+ "version": "6.2.3"
100
100
  }
@@ -19,9 +19,9 @@ import {
19
19
  } from './constants.js';
20
20
  import { trimWhitespace, collapseWhitespaceAll } from './whitespace.js';
21
21
  import { shouldMinifyInnerHTML } from './options.js';
22
- import { isThenable } from './utils.js';
22
+ import { identity, isThenable } from './utils.js';
23
23
 
24
- // Lazy-load entities only when `decodeEntities` is enabled
24
+ // Lazy-load entities (used for `decodeEntities` and event-handler attribute decode before `minifyJS`)
25
25
 
26
26
  let decodeHTMLStrictPromise;
27
27
  async function getDecodeHTMLStrict() {
@@ -317,6 +317,23 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs, minifyHTM
317
317
 
318
318
  if (isEventAttr) {
319
319
  attrValue = trimWhitespace(attrValue).replace(/^javascript:\s*/i, '');
320
+ // Browsers decode attribute values before running event-handler JS—
321
+ // decode first so the minifier gets valid JavaScript
322
+ if (!options.decodeEntities && options.minifyJS !== identity && attrValue.indexOf('&') !== -1) {
323
+ return getDecodeHTMLStrict().then(decode => {
324
+ const decoded = decode(attrValue);
325
+ const result = options.minifyJS(decoded, true);
326
+ const reEncode = v => (v && v.indexOf('&') !== -1) ? v.replace(RE_AMP_ENTITY, '&$1') : v;
327
+ if (isThenable(result)) {
328
+ return result.then(reEncode, err => {
329
+ if (!options.continueOnMinifyError) throw err;
330
+ options.log && options.log(err);
331
+ return attrValue;
332
+ });
333
+ }
334
+ return reEncode(result);
335
+ });
336
+ }
320
337
  const result = options.minifyJS(attrValue, true);
321
338
  if (isThenable(result)) {
322
339
  return result.catch(err => {