url-sanitizer 4.2.2 → 5.0.0

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.
package/package.json CHANGED
@@ -25,52 +25,49 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "dompurify": "^3.4.12",
29
- "jsdom": "^29.1.1"
28
+ "dompurify": "^3.4.13",
29
+ "jsdom": "^30.0.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@braintree/sanitize-url": "^7.1.2",
33
- "@types/jsdom": "^28.0.3",
34
- "@types/node": "^26.1.1",
33
+ "@types/jsdom": "^30.0.0",
34
+ "@types/node": "^26.2.0",
35
35
  "c8": "^12.0.0",
36
36
  "chai": "^6.2.2",
37
37
  "commander": "^15.0.0",
38
38
  "copyfiles-ng": "^2.4.7",
39
- "esbuild": "^0.28.1",
39
+ "esbuild": "^0.28.2",
40
40
  "eslint": "^9.39.5",
41
41
  "eslint-config-prettier": "^10.1.8",
42
- "eslint-plugin-jsdoc": "^63.3.0",
42
+ "eslint-plugin-jsdoc": "^64.1.0",
43
43
  "eslint-plugin-prettier": "^5.5.6",
44
44
  "eslint-plugin-regexp": "^3.1.1",
45
45
  "eslint-plugin-unicorn": "^64.0.0",
46
46
  "fast-check": "^4.9.0",
47
- "globals": "^17.8.0",
47
+ "globals": "^17.11.0",
48
48
  "http-server": "^14.1.1",
49
49
  "mitata": "^1.0.34",
50
- "mocha": "^11.7.6",
50
+ "mocha": "^11.8.0",
51
51
  "neostandard": "^0.13.0",
52
52
  "papaparse": "^5.5.4",
53
53
  "prettier": "^3.9.6",
54
54
  "sinon": "^22.1.0",
55
55
  "strict-url-sanitise": "^0.0.1",
56
56
  "typescript": "^7.0.2",
57
- "undici": "^8.9.0"
57
+ "undici": "^8.10.0"
58
58
  },
59
59
  "overrides": {
60
- "c8": {
61
- "yargs": "^18.0.0"
62
- },
63
60
  "eslint": {
64
- "js-yaml": "^4.3.0"
61
+ "js-yaml": "^4.3.1"
65
62
  },
66
63
  "mocha": {
67
64
  "diff": "^8.0.3",
68
- "js-yaml": "^4.3.0"
69
- },
70
- "serialize-javascript": "^7.0.4"
65
+ "js-yaml": "^4.3.1",
66
+ "serialize-javascript": "^7.0.7"
67
+ }
71
68
  },
72
69
  "allowScripts": {
73
- "esbuild@0.28.1": true
70
+ "esbuild@0.28.2": true
74
71
  },
75
72
  "scripts": {
76
73
  "bench": "node benchmark/benchmark.js",
@@ -91,7 +88,7 @@
91
88
  "tsc": "node scripts/index clean --dir=types -i && npx tsc"
92
89
  },
93
90
  "engines": {
94
- "node": ">=22.13"
91
+ "node": "^22.22.2 || ^24.15.0 || >=26.0.0"
95
92
  },
96
- "version": "4.2.2"
93
+ "version": "5.0.0"
97
94
  }
package/src/index.js CHANGED
@@ -9,11 +9,8 @@
9
9
  export {
10
10
  default,
11
11
  inspectURL,
12
- inspectURLSync,
13
- isURI,
14
- isURISync,
15
- parseURL,
16
- parseURLSync,
12
+ isURISync, // deprecated
13
+ isValidURI,
17
14
  sanitizeURL,
18
15
  sanitizeURLSync
19
16
  } from './mjs/sanitizer.js';
@@ -1 +1 @@
1
- ["aaa","aaas","about","acap","acct","acd","acr","adiumxtra","adt","afp","afs","agtp","aim","amss","android","appdata","apt","ar","ari","ark","at","attachment","aw","barion","beshare","bitcoin","bitcoincash","bl","blob","bluetooth","bolo","brid","browserext","cabal","caip","calculator","callto","cap","cast","casts","chrome","chrome-extension","cid","coap","coaps","com-eventbrite-attendee","content","content-type","crid","cstr","cttps","cvs","dab","dat","data","dav","dhttp","diaspora","dict","did","dilithium3","dis","dlna-playcontainer","dlna-playsingle","dnp","dns","dntp","doi","donau","dpp","drm","dtmi","dtn","dvb","dvx","dweb","ed2k","eid","elsi","embedded","ens","esim","ethereum","example","ez","facetime","feed","feedready","fido","file","finger","first-run-pen-experience","fish","fm","ftp","fuchsia-pkg","geo","gg","git","gitoid","gizmoproject","go","gopher","graph","gtalk","h323","ham","hcap","hcp","hs20","http","https","hxxp","hxxps","hydrazone","hyper","i0","iax","ibi","ibi-","icap","icon","ilstring","im","imap","info","iotdisco","ipfs","ipn","ipns","ipp","ipps","irc","irc6","ircs","iris","iris.beep","iris.lwz","iris.xpc","iris.xpcs","isostore","itms","jabber","jar","jms","keyparc","lastfm","lbry","ldap","ldaps","leaptofrogans","lid","linkid","lorawan","lpa","lvlt","machineProvisioningProgressReporter","magnet","mailto","maps","market","matrix","mdoc","mdoc-openid4vp","message","microsoft.windows.camera","microsoft.windows.camera.multipicker","microsoft.windows.camera.picker","mid","mms","mongodb","moz","moz-extension","mqtt","mqtts","ms-access","ms-appinstaller","ms-browser-extension","ms-calculator","ms-drive-to","ms-enrollment","ms-excel","ms-eyecontrolspeech","ms-gamebarservices","ms-gamingoverlay","ms-getoffice","ms-help","ms-infopath","ms-inputapp","ms-launchremotedesktop","ms-lockscreencomponent-config","ms-media-stream-id","ms-meetnow","ms-mixedrealitycapture","ms-mobileplans","ms-newsandinterests","ms-officeapp","ms-people","ms-personacard","ms-powerpoint","ms-project","ms-publisher","ms-recall","ms-remotedesktop","ms-remotedesktop-launch","ms-restoretabcompanion","ms-screenclip","ms-screensketch","ms-search","ms-search-repair","ms-secondary-screen-controller","ms-secondary-screen-setup","ms-settings","ms-settings-airplanemode","ms-settings-bluetooth","ms-settings-camera","ms-settings-cellular","ms-settings-cloudstorage","ms-settings-connectabledevices","ms-settings-displays-topology","ms-settings-emailandaccounts","ms-settings-language","ms-settings-location","ms-settings-lock","ms-settings-nfctransactions","ms-settings-notifications","ms-settings-power","ms-settings-privacy","ms-settings-proximity","ms-settings-screenrotation","ms-settings-wifi","ms-settings-workplace","ms-spd","ms-stickers","ms-sttoverlay","ms-transit-to","ms-useractivityset","ms-uup","ms-virtualtouchpad","ms-visio","ms-walk-to","ms-whiteboard","ms-whiteboard-cmd","ms-widgetboard","ms-widgets","ms-word","msnim","msrp","msrps","mss","mt","mtqp","mtrust","mumble","mupdate","musik","mvn","mvrp","mvrps","news","nfs","ni","nih","nntp","nostr","notes","npamp","num","ocf","oid","onenote","onenote-cmd","opaquelocktoken","openid","openpgp4fpr","otpauth","palm","paparazzi","payto","pkcs11","platform","pop","pres","proxy","psyc","pttp","pwid","qb","query","quic-transport","redis","rediss","reload","res","resource","rmi","rsync","rtmfp","rtmp","rtsp","rtsps","rtspu","sarif","secondlife","secret-token","service","session","sftp","sgn","shc","shelter","sieve","simpleledger","simplex","sip","sips","skype","smb","smp","sms","smtp","snmp","soap.beep","soap.beeps","soldat","spacify","spiffe","spotify","ssb","ssh","sss","starknet","steam","stun","stuns","submit","svn","swh","swid","swidpath","tag","taler","teamspeak","teapot","teapots","tel","teliaeid","telnet","tftp","things","thismessage","tip","tn3270","tool","tttps","turn","turns","tv","udp","unreal","upn","urn","ust","ut2004","uuaid","uuid-in-package","v-event","vemmi","ventrilo","ves","view-source","vnc","vscode","vscode-insiders","vsls","w3","wasm","wasm-js","wcr","web3","webcal","wifi","ws","wss","wtai","wyciwyg","xcompute","xcon","xcon-userid","xfire","xftp","xmlrpc.beep","xmlrpc.beeps","xmpp","xrcp","xri","ymsgr","z39.50r","z39.50s","ztdnaid"]
1
+ ["aaa","aaas","about","acap","acct","acd","acr","adiumxtra","adt","aet","afp","afs","agtp","aim","amss","android","appdata","apt","ar","ari","ark","at","attachment","aw","barion","beshare","bitcoin","bitcoincash","bl","blob","bluetooth","bolo","brid","browserext","cabal","caip","calculator","callto","cap","cast","casts","chrome","chrome-extension","cid","cm","coap","coaps","com-eventbrite-attendee","content","content-type","crid","cstr","cttps","cvs","dab","dat","data","dav","dhttp","diaspora","dict","did","dilithium3","dis","dlna-playcontainer","dlna-playsingle","dnp","dns","dntp","doi","donau","dpp","drm","dtmi","dtn","dvb","dvx","dweb","ed2k","eid","elsi","embedded","ens","esim","ethereum","example","ez","facetime","feed","feedready","fido","file","finger","first-run-pen-experience","fish","fm","ftp","fuchsia-pkg","gcx","gdsi","geo","gg","git","gitoid","gizmoproject","go","gopher","graph","gtalk","h323","ham","hcap","hcp","hs20","http","https","hxxp","hxxps","hydrazone","hyper","i0","iax","ibi","ibi-","icap","icon","ilstring","im","imap","info","iotdisco","ipfs","ipn","ipns","ipp","ipps","irc","irc6","ircs","iris","iris.beep","iris.lwz","iris.xpc","iris.xpcs","isostore","itms","jabber","jar","jms","keyparc","lastfm","lbry","ldap","ldaps","leaptofrogans","lid","linkid","lorawan","lpa","lvlt","machineProvisioningProgressReporter","magnet","mailto","maps","market","matrix","mdoc","mdoc-openid4vp","message","microsoft.windows.camera","microsoft.windows.camera.multipicker","microsoft.windows.camera.picker","mid","mms","mongodb","moz","moz-extension","mqtt","mqtts","ms-access","ms-appinstaller","ms-browser-extension","ms-calculator","ms-drive-to","ms-enrollment","ms-excel","ms-eyecontrolspeech","ms-gamebarservices","ms-gamingoverlay","ms-getoffice","ms-help","ms-infopath","ms-inputapp","ms-launchremotedesktop","ms-lockscreencomponent-config","ms-media-stream-id","ms-meetnow","ms-mixedrealitycapture","ms-mobileplans","ms-newsandinterests","ms-officeapp","ms-people","ms-personacard","ms-powerpoint","ms-project","ms-publisher","ms-recall","ms-remotedesktop","ms-remotedesktop-launch","ms-restoretabcompanion","ms-screenclip","ms-screensketch","ms-search","ms-search-repair","ms-secondary-screen-controller","ms-secondary-screen-setup","ms-settings","ms-settings-airplanemode","ms-settings-bluetooth","ms-settings-camera","ms-settings-cellular","ms-settings-cloudstorage","ms-settings-connectabledevices","ms-settings-displays-topology","ms-settings-emailandaccounts","ms-settings-language","ms-settings-location","ms-settings-lock","ms-settings-nfctransactions","ms-settings-notifications","ms-settings-power","ms-settings-privacy","ms-settings-proximity","ms-settings-screenrotation","ms-settings-wifi","ms-settings-workplace","ms-spd","ms-stickers","ms-sttoverlay","ms-transit-to","ms-useractivityset","ms-uup","ms-virtualtouchpad","ms-visio","ms-walk-to","ms-whiteboard","ms-whiteboard-cmd","ms-widgetboard","ms-widgets","ms-word","msnim","msrp","msrps","mss","mt","mtqp","mtrust","mumble","mupdate","musik","mvn","mvrp","mvrps","news","nfs","ni","nih","nntp","nostr","notes","npamp","num","ocf","oid","onenote","onenote-cmd","opaquelocktoken","openid","openpgp4fpr","otpauth","palm","paparazzi","payto","pkcs11","pkg","platform","pop","pres","proxy","psyc","pttp","pwid","qb","query","quic-transport","redis","rediss","reload","res","resource","rmi","rsync","rtmfp","rtmp","rtsp","rtsps","rtspu","sarif","secondlife","secret-token","service","session","sftp","sgn","shc","shelter","sieve","simpleledger","simplex","sip","sips","skype","smb","smp","sms","smtp","snmp","soap.beep","soap.beeps","soldat","spacify","spiffe","spotify","ssb","ssh","sss","starknet","steam","stun","stuns","submit","svn","swh","swid","swidpath","tag","taler","teamspeak","teapot","teapots","tel","teliaeid","telnet","tftp","things","thismessage","tip","tn3270","tool","tttps","turn","turns","tv","udp","unreal","upn","urn","ust","ut2004","uuaid","uuid-in-package","v-event","vemmi","ventrilo","ves","view-source","vnc","vscode","vscode-insiders","vsls","w3","wasm","wasm-js","wcr","web3","webcal","wifi","ws","wss","wtai","wyciwyg","xcompute","xcon","xcon-userid","xfire","xftp","xmlrpc.beep","xmlrpc.beeps","xmpp","xrcp","xri","ymsgr","z39.50r","z39.50s","ztdnaid"]
@@ -2,6 +2,12 @@
2
2
  * constant.js
3
3
  */
4
4
 
5
+ /**
6
+ * The total number of 8-bit byte values (0x00–0xFF).
7
+ * @type {number}
8
+ */
9
+ export const BYTE_RANGE = 256;
10
+
5
11
  /**
6
12
  * Chunk size (8KB) used when processing byte arrays to avoid stack overflow.
7
13
  * @type {number}
@@ -32,6 +38,18 @@ export const MAX_BLOB_SIZE = 16 * 1024 * 1024;
32
38
  */
33
39
  export const MAX_NEST = 16;
34
40
 
41
+ /**
42
+ * Maximum URL length (64KB).
43
+ * @type {number}
44
+ */
45
+ export const MAX_URL_LENGTH = 64 * 1024;
46
+
47
+ /**
48
+ * Length used for truncating string.
49
+ * @type {number}
50
+ */
51
+ export const TRUNCATE_LENGTH = 64;
52
+
35
53
  /**
36
54
  * Start index used to extract the type name from Object.prototype.toString().
37
55
  * (e.g. removes "[object " prefix)
package/src/mjs/regexp.js CHANGED
@@ -12,7 +12,7 @@ export const REG_CHARSET = /^charset\s*=\s*(["']?)(?<name>[\w:-]+)\1$/;
12
12
  * Matches a trailing empty fragment identifier (#).
13
13
  * @type {RegExp}
14
14
  */
15
- export const REG_HASH = /(?:#|%23)$/;
15
+ export const REG_HASH = /#$/;
16
16
 
17
17
  /**
18
18
  * Matches MIME types that contain DOM-parsable content (HTML, XML, SVG).
@@ -25,10 +25,10 @@ export const REG_MIME_DOM =
25
25
  * Matches general text MIME types.
26
26
  * @type {RegExp}
27
27
  */
28
- export const REG_MIME_TEXT = /^text\/[\w#&.;-]+/;
28
+ export const REG_MIME_TEXT = /^text\/[\w#&.;+-]+/i;
29
29
 
30
30
  /**
31
- * Matches numeric character reference.
31
+ * Matches numeric character references (hex or decimal).
32
32
  * @type {RegExp}
33
33
  */
34
34
  export const REG_NUM_REF = /&#(x0*[\dA-F]{1,2}|0*\d{1,3});?/gi;
@@ -37,7 +37,7 @@ export const REG_NUM_REF = /&#(x0*[\dA-F]{1,2}|0*\d{1,3});?/gi;
37
37
  * Matches a trailing empty query string (?), ensuring it is not part of a hash.
38
38
  * @type {RegExp}
39
39
  */
40
- export const REG_QUERY = /^((?:[^#%]|%(?!23))*)(?:\?|%3F)$/i;
40
+ export const REG_QUERY = /^((?:[^#%]|%(?!23))*)\?$/;
41
41
 
42
42
  /**
43
43
  * Validates a string against standard IANA URI scheme syntax.
@@ -63,10 +63,10 @@ export const REG_SCRIPT = /^(?:java|vb)script$/i;
63
63
  * Matches script-executing or data-fetching schemes.
64
64
  * @type {RegExp}
65
65
  */
66
- export const REG_SCRIPT_BLOB = /^(?:(?:java|vb)script|blob)$/i;
66
+ export const REG_SCRIPT_OR_BLOB = /^(?:(?:java|vb)script|blob)$/i;
67
67
 
68
68
  /**
69
- * Matches HTML tags, quotes, and their encoded or character reference variants.
69
+ * Matches HTML-sensitive characters and their encoded variants.
70
70
  * @type {RegExp}
71
71
  */
72
72
  export const REG_TAG_QUOT =
@@ -79,19 +79,25 @@ export const REG_TAG_QUOT =
79
79
  export const REG_URL_ENC = /^%[\dA-F]{2}$/i;
80
80
 
81
81
  /**
82
- * Matches an ampersand-encoded character (&foo).
82
+ * Matches one or more consecutive percent-encoded sequences (%20, %E3%81%82).
83
83
  * @type {RegExp}
84
84
  */
85
- export const REG_AMP_ENC = /&(?=[#a-z0-9])(?![a-z0-9]+=)/i;
85
+ export const REG_PCT_ENC = /(?:%[\dA-F]{2})+/gi;
86
86
 
87
87
  /**
88
- * Match one or more consecutive URL percent-encoded sequences (%20, %E3%81%82).
88
+ * Matches HTML-encoded ampersands.
89
89
  * @type {RegExp}
90
90
  */
91
- export const REG_PCT_ENC = /(?:%[\dA-F]{2})+/gi;
91
+ export const REG_AMP = /&amp;/gi;
92
+
93
+ /**
94
+ * Matches ampersand that may begin an HTML entity reference.
95
+ * @type {RegExp}
96
+ */
97
+ export const REG_AMP_ENC = /&(?=[#a-z0-9])(?![a-z0-9]+=)/i;
92
98
 
93
99
  /**
94
- * Validates relative URLs and flags invalid patterns.
100
+ * Matches invalid relative URL patterns.
95
101
  * @type {RegExp}
96
102
  */
97
103
  export const REG_VERIFY_RELATIVE = /^(?:\/{2,}|\\|[a-z][a-z\d+\-.]*:[^/])/i;