html-minifier-next 6.2.1 → 6.2.2

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.
@@ -43,6 +43,17 @@ class LRU {
43
43
  delete(key) { this.map.delete(key); }
44
44
  }
45
45
 
46
+ // FNV-1a 32-bit hash for large-input cache keys
47
+
48
+ function hashContent(str) {
49
+ let hash = 2166136261;
50
+ for (let i = 0; i < str.length; i++) {
51
+ hash ^= str.charCodeAt(i);
52
+ hash = Math.imul(hash, 16777619);
53
+ }
54
+ return (hash >>> 0).toString(36);
55
+ }
56
+
46
57
  // Unique ID generator
47
58
 
48
59
  function uniqueId(value) {
@@ -1816,12 +1827,11 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
1816
1827
  );
1817
1828
  }
1818
1829
 
1819
- // Cache key: Wrapped content, type, options signature
1830
+ // Cache key: Content + type + options signature; large inputs are hashed to avoid huge Map keys
1820
1831
  const inputCSS = wrapCSS(text, type);
1821
1832
  const cssSig = stableStringify({ type, opts: lightningCssOptions, cont: !!options.continueOnMinifyError });
1822
- // For large inputs, use length and content fingerprint (first/last 50 chars) to prevent collisions
1823
1833
  const cssKey = inputCSS.length > 2048
1824
- ? (inputCSS.length + '|' + inputCSS.slice(0, 50) + inputCSS.slice(-50) + '|' + type + '|' + cssSig)
1834
+ ? (hashContent(inputCSS) + '|' + type + '|' + cssSig)
1825
1835
  : (inputCSS + '|' + type + '|' + cssSig);
1826
1836
 
1827
1837
  try {
@@ -1931,8 +1941,8 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
1931
1941
  // Select pre-computed signature based on engine
1932
1942
  const optsSig = useEngine === 'terser' ? terserSig : swcSig;
1933
1943
 
1934
- // For large inputs, use length and content fingerprint to prevent collisions
1935
- jsKey = (code.length > 2048 ? (code.length + '|' + code.slice(0, 50) + code.slice(-50) + '|') : (code + '|'))
1944
+ // For large inputs, hash the full content to avoid storing huge strings as Map keys
1945
+ jsKey = (code.length > 2048 ? (hashContent(code) + '|') : (code + '|'))
1936
1946
  + (inline ? '1' : '0') + '|' + (isModule ? 'm' : '') + '|' + useEngine + '|' + optsSig;
1937
1947
 
1938
1948
  const cached = jsMinifyCache.get(jsKey);
@@ -2044,9 +2054,9 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
2044
2054
  return svgContent;
2045
2055
  }
2046
2056
 
2047
- // Cache key
2057
+ // Cache key: Large inputs are hashed to avoid huge Map keys
2048
2058
  const svgKey = svgContent.length > 2048
2049
- ? (svgContent.length + '|' + svgContent.slice(0, 50) + svgContent.slice(-50) + '|' + svgSig)
2059
+ ? (hashContent(svgContent) + '|' + svgSig)
2050
2060
  : (svgContent + '|' + svgSig);
2051
2061
 
2052
2062
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/lib/options.js"],"names":[],"mappings":"AAYA,6DAUC;AAID;;;;;;;;;;;GAWG;AACH,6CAXW,OAAO,CAAC,eAAe,CAAC,mGAEhC;IAAuB,eAAe;IACf,SAAS;IACT,MAAM;CAA2B,GAK9C,eAAe,CAiX3B"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/lib/options.js"],"names":[],"mappings":"AAYA,6DAUC;AAID;;;;;;;;;;;GAWG;AACH,6CAXW,OAAO,CAAC,eAAe,CAAC,mGAEhC;IAAuB,eAAe;IACf,SAAS;IACT,MAAM;CAA2B,GAK9C,eAAe,CAgX3B"}
@@ -7,6 +7,7 @@ export class LRU {
7
7
  set(key: any, value: any): void;
8
8
  delete(key: any): void;
9
9
  }
10
+ export function hashContent(str: any): string;
10
11
  export function uniqueId(value: any): string;
11
12
  export function identity(value: any): any;
12
13
  export function isThenable(value: any): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils.js"],"names":[],"mappings":"AAEA,+CAUC;AAID;IACE,4BAGC;IAFC,cAAkB;IAClB,mBAAoB;IAEtB,mBAQC;IACD,gCAOC;IACD,uBAAqC;CACtC;AAID,6CAMC;AAID,0CAEC;AAED,gDAEC;AAED,2CAEC;AAID;;;;;;GAMG;AACH,kCALW,MAAM,SACN,MAAM,sBAEJ,OAAO,CAAC,MAAM,CAAC,CAY3B;AAID,6CAUC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils.js"],"names":[],"mappings":"AAEA,+CAUC;AAID;IACE,4BAGC;IAFC,cAAkB;IAClB,mBAAoB;IAEtB,mBAQC;IACD,gCAOC;IACD,uBAAqC;CACtC;AAID,8CAOC;AAID,6CAMC;AAID,0CAEC;AAED,gDAEC;AAED,2CAEC;AAID;;;;;;GAMG;AACH,kCALW,MAAM,SACN,MAAM,sBAEJ,OAAO,CAAC,MAAM,CAAC,CAY3B;AAID,6CAUC"}
package/package.json CHANGED
@@ -96,5 +96,5 @@
96
96
  },
97
97
  "type": "module",
98
98
  "types": "./dist/types/htmlminifier.d.ts",
99
- "version": "6.2.1"
99
+ "version": "6.2.2"
100
100
  }
@@ -1,7 +1,7 @@
1
1
  // Imports
2
2
 
3
3
  import { createUrlMinifier } from './urls.js';
4
- import { LRU, stableStringify, identity, lowercase, replaceAsync, parseRegExp } from './utils.js';
4
+ import { LRU, stableStringify, hashContent, identity, lowercase, replaceAsync, parseRegExp } from './utils.js';
5
5
  import { RE_TRAILING_SEMICOLON } from './constants.js';
6
6
  import { canCollapseWhitespace, canTrimWhitespace } from './whitespace.js';
7
7
  import { wrapCSS, unwrapCSS } from './content.js';
@@ -131,12 +131,11 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
131
131
  );
132
132
  }
133
133
 
134
- // Cache key: Wrapped content, type, options signature
134
+ // Cache key: Content + type + options signature; large inputs are hashed to avoid huge Map keys
135
135
  const inputCSS = wrapCSS(text, type);
136
136
  const cssSig = stableStringify({ type, opts: lightningCssOptions, cont: !!options.continueOnMinifyError });
137
- // For large inputs, use length and content fingerprint (first/last 50 chars) to prevent collisions
138
137
  const cssKey = inputCSS.length > 2048
139
- ? (inputCSS.length + '|' + inputCSS.slice(0, 50) + inputCSS.slice(-50) + '|' + type + '|' + cssSig)
138
+ ? (hashContent(inputCSS) + '|' + type + '|' + cssSig)
140
139
  : (inputCSS + '|' + type + '|' + cssSig);
141
140
 
142
141
  try {
@@ -246,8 +245,8 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
246
245
  // Select pre-computed signature based on engine
247
246
  const optsSig = useEngine === 'terser' ? terserSig : swcSig;
248
247
 
249
- // For large inputs, use length and content fingerprint to prevent collisions
250
- jsKey = (code.length > 2048 ? (code.length + '|' + code.slice(0, 50) + code.slice(-50) + '|') : (code + '|'))
248
+ // For large inputs, hash the full content to avoid storing huge strings as Map keys
249
+ jsKey = (code.length > 2048 ? (hashContent(code) + '|') : (code + '|'))
251
250
  + (inline ? '1' : '0') + '|' + (isModule ? 'm' : '') + '|' + useEngine + '|' + optsSig;
252
251
 
253
252
  const cached = jsMinifyCache.get(jsKey);
@@ -359,9 +358,9 @@ const processOptions = (inputOptions, { getLightningCSS, getTerser, getSwc, getS
359
358
  return svgContent;
360
359
  }
361
360
 
362
- // Cache key
361
+ // Cache key: Large inputs are hashed to avoid huge Map keys
363
362
  const svgKey = svgContent.length > 2048
364
- ? (svgContent.length + '|' + svgContent.slice(0, 50) + svgContent.slice(-50) + '|' + svgSig)
363
+ ? (hashContent(svgContent) + '|' + svgSig)
365
364
  : (svgContent + '|' + svgSig);
366
365
 
367
366
  try {
package/src/lib/utils.js CHANGED
@@ -39,6 +39,17 @@ class LRU {
39
39
  delete(key) { this.map.delete(key); }
40
40
  }
41
41
 
42
+ // FNV-1a 32-bit hash for large-input cache keys
43
+
44
+ function hashContent(str) {
45
+ let hash = 2166136261;
46
+ for (let i = 0; i < str.length; i++) {
47
+ hash ^= str.charCodeAt(i);
48
+ hash = Math.imul(hash, 16777619);
49
+ }
50
+ return (hash >>> 0).toString(36);
51
+ }
52
+
42
53
  // Unique ID generator
43
54
 
44
55
  function uniqueId(value) {
@@ -102,6 +113,7 @@ function parseRegExp(value) {
102
113
 
103
114
  export { stableStringify };
104
115
  export { LRU };
116
+ export { hashContent };
105
117
  export { uniqueId };
106
118
  export { identity };
107
119
  export { isThenable };