js-md5 0.9.2 → 0.11.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.
@@ -13,7 +13,7 @@ var md5$1 = {exports: {}};
13
13
  * [js-md5]{@link https://github.com/emn178/js-md5}
14
14
  *
15
15
  * @namespace md5
16
- * @version 0.9.2
16
+ * @version 0.11.0
17
17
  * @author Chen, Yi-Cyuan [emn178@gmail.com]
18
18
  * @copyright Chen, Yi-Cyuan 2014-2026
19
19
  * @license MIT
@@ -70,7 +70,7 @@ var md5$1 = {exports: {}};
70
70
  };
71
71
  }
72
72
 
73
- var isView = ArrayBuffer.isView;
73
+ var isView = ARRAY_BUFFER ? ArrayBuffer.isView : null;
74
74
  /* istanbul ignore else */
75
75
  if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
76
76
  isView = function (obj) {
@@ -90,10 +90,14 @@ var md5$1 = {exports: {}};
90
90
  if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
91
91
  return [new Uint8Array(message), false];
92
92
  }
93
- if (!isArray(message) && !isView(message)) {
93
+ if (isArray(message)) {
94
+ return [message, false];
95
+ }
96
+ if (!ARRAY_BUFFER || !isView(message)) {
94
97
  throw new Error(INPUT_ERROR);
95
98
  }
96
- return [message, false];
99
+ // read the underlying bytes of any view (DataView, Uint16Array, ...)
100
+ return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
97
101
  };
98
102
 
99
103
  /**
@@ -214,6 +218,8 @@ var md5$1 = {exports: {}};
214
218
  throw new Error(INPUT_ERROR);
215
219
  } else if (message.constructor === ArrayBuffer) {
216
220
  message = new Uint8Array(message);
221
+ } else if (ARRAY_BUFFER && isView(message) && message.constructor !== Buffer) {
222
+ message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
217
223
  }
218
224
  }
219
225
  if (isArray(message) || isView(message) ||
@@ -381,7 +387,7 @@ var md5$1 = {exports: {}};
381
387
  var result = formatMessage(message);
382
388
  message = result[0];
383
389
  var isString = result[1];
384
- var code, index = 0, i, length = message.length, blocks = this.blocks;
390
+ var code, code2, index = 0, i, length = message.length, blocks = this.blocks;
385
391
  var buffer8 = this.buffer8;
386
392
 
387
393
  while (index < length) {
@@ -407,12 +413,18 @@ var md5$1 = {exports: {}};
407
413
  buffer8[i++] = 0xe0 | (code >>> 12);
408
414
  buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
409
415
  buffer8[i++] = 0x80 | (code & 0x3f);
410
- } else {
411
- code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
416
+ } else if (code < 0xdc00 && (code2 = message.charCodeAt(index + 1)) >= 0xdc00 && code2 < 0xe000) {
417
+ ++index;
418
+ code = 0x10000 + (((code & 0x3ff) << 10) | (code2 & 0x3ff));
412
419
  buffer8[i++] = 0xf0 | (code >>> 18);
413
420
  buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f);
414
421
  buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
415
422
  buffer8[i++] = 0x80 | (code & 0x3f);
423
+ } else {
424
+ // unpaired surrogate: U+FFFD
425
+ buffer8[i++] = 0xef;
426
+ buffer8[i++] = 0xbf;
427
+ buffer8[i++] = 0xbd;
416
428
  }
417
429
  }
418
430
  } else {
@@ -427,12 +439,18 @@ var md5$1 = {exports: {}};
427
439
  blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
428
440
  blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
429
441
  blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
430
- } else {
431
- code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
442
+ } else if (code < 0xdc00 && (code2 = message.charCodeAt(index + 1)) >= 0xdc00 && code2 < 0xe000) {
443
+ ++index;
444
+ code = 0x10000 + (((code & 0x3ff) << 10) | (code2 & 0x3ff));
432
445
  blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
433
446
  blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
434
447
  blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
435
448
  blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
449
+ } else {
450
+ // unpaired surrogate: U+FFFD
451
+ blocks[i >>> 2] |= 0xef << SHIFT[i++ & 3];
452
+ blocks[i >>> 2] |= 0xbf << SHIFT[i++ & 3];
453
+ blocks[i >>> 2] |= 0xbd << SHIFT[i++ & 3];
436
454
  }
437
455
  }
438
456
  }
@@ -815,7 +833,7 @@ var md5$1 = {exports: {}};
815
833
  var i, result = formatMessage(key);
816
834
  key = result[0];
817
835
  if (result[1]) {
818
- var bytes = [], length = key.length, index = 0, code;
836
+ var bytes = [], length = key.length, index = 0, code, code2;
819
837
  for (i = 0; i < length; ++i) {
820
838
  code = key.charCodeAt(i);
821
839
  if (code < 0x80) {
@@ -827,12 +845,18 @@ var md5$1 = {exports: {}};
827
845
  bytes[index++] = (0xe0 | (code >>> 12));
828
846
  bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
829
847
  bytes[index++] = (0x80 | (code & 0x3f));
830
- } else {
831
- code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
848
+ } else if (code < 0xdc00 && (code2 = key.charCodeAt(i + 1)) >= 0xdc00 && code2 < 0xe000) {
849
+ ++i;
850
+ code = 0x10000 + (((code & 0x3ff) << 10) | (code2 & 0x3ff));
832
851
  bytes[index++] = (0xf0 | (code >>> 18));
833
852
  bytes[index++] = (0x80 | ((code >>> 12) & 0x3f));
834
853
  bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
835
854
  bytes[index++] = (0x80 | (code & 0x3f));
855
+ } else {
856
+ // unpaired surrogate: U+FFFD
857
+ bytes[index++] = 0xef;
858
+ bytes[index++] = 0xbf;
859
+ bytes[index++] = 0xbd;
836
860
  }
837
861
  }
838
862
  key = bytes;
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type Message = string | number[] | ArrayBuffer | Uint8Array;
1
+ type Message = string | number[] | ArrayBuffer | ArrayBufferView;
2
2
 
3
3
  interface Hasher {
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-md5",
3
- "version": "0.9.2",
3
+ "version": "0.11.0",
4
4
  "description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.",
5
5
  "main": "src/md5.js",
6
6
  "module": "build/md5.mjs",
@@ -77,5 +77,11 @@
77
77
  "browser": {
78
78
  "crypto": false,
79
79
  "buffer": false
80
+ },
81
+ "overrides": {
82
+ "diff": "^8.0.3",
83
+ "glob": "^14.0.2",
84
+ "minimatch": "^11.0.1",
85
+ "serialize-javascript": "^7.1.3"
80
86
  }
81
87
  }
package/src/md5.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * [js-md5]{@link https://github.com/emn178/js-md5}
3
3
  *
4
4
  * @namespace md5
5
- * @version 0.9.2
5
+ * @version 0.11.0
6
6
  * @author Chen, Yi-Cyuan [emn178@gmail.com]
7
7
  * @copyright Chen, Yi-Cyuan 2014-2026
8
8
  * @license MIT
@@ -66,7 +66,7 @@
66
66
  };
67
67
  }
68
68
 
69
- var isView = ArrayBuffer.isView;
69
+ var isView = ARRAY_BUFFER ? ArrayBuffer.isView : null;
70
70
  /* istanbul ignore else */
71
71
  if (FEATURE_LEGACY && ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
72
72
  isView = function (obj) {
@@ -86,11 +86,15 @@
86
86
  if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
87
87
  return [new Uint8Array(message), false];
88
88
  }
89
- if (!isArray(message) && !isView(message)) {
89
+ if (isArray(message)) {
90
+ return [message, false];
91
+ }
92
+ if (!ARRAY_BUFFER || !isView(message)) {
90
93
  throw new Error(INPUT_ERROR);
91
94
  }
92
- return [message, false];
93
- }
95
+ // read the underlying bytes of any view (DataView, Uint16Array, ...)
96
+ return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
97
+ };
94
98
 
95
99
  /**
96
100
  * @method hex
@@ -210,6 +214,8 @@
210
214
  throw new Error(INPUT_ERROR);
211
215
  } else if (message.constructor === ArrayBuffer) {
212
216
  message = new Uint8Array(message);
217
+ } else if (ARRAY_BUFFER && isView(message) && message.constructor !== Buffer) {
218
+ message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
213
219
  }
214
220
  }
215
221
  if (isArray(message) || isView(message) ||
@@ -377,7 +383,7 @@
377
383
  var result = formatMessage(message);
378
384
  message = result[0];
379
385
  var isString = result[1];
380
- var code, index = 0, i, length = message.length, blocks = this.blocks;
386
+ var code, code2, index = 0, i, length = message.length, blocks = this.blocks;
381
387
  var buffer8 = this.buffer8;
382
388
 
383
389
  while (index < length) {
@@ -403,12 +409,18 @@
403
409
  buffer8[i++] = 0xe0 | (code >>> 12);
404
410
  buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
405
411
  buffer8[i++] = 0x80 | (code & 0x3f);
406
- } else {
407
- code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
412
+ } else if (code < 0xdc00 && (code2 = message.charCodeAt(index + 1)) >= 0xdc00 && code2 < 0xe000) {
413
+ ++index;
414
+ code = 0x10000 + (((code & 0x3ff) << 10) | (code2 & 0x3ff));
408
415
  buffer8[i++] = 0xf0 | (code >>> 18);
409
416
  buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f);
410
417
  buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
411
418
  buffer8[i++] = 0x80 | (code & 0x3f);
419
+ } else {
420
+ // unpaired surrogate: U+FFFD
421
+ buffer8[i++] = 0xef;
422
+ buffer8[i++] = 0xbf;
423
+ buffer8[i++] = 0xbd;
412
424
  }
413
425
  }
414
426
  } else {
@@ -423,12 +435,18 @@
423
435
  blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
424
436
  blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
425
437
  blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
426
- } else {
427
- code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
438
+ } else if (code < 0xdc00 && (code2 = message.charCodeAt(index + 1)) >= 0xdc00 && code2 < 0xe000) {
439
+ ++index;
440
+ code = 0x10000 + (((code & 0x3ff) << 10) | (code2 & 0x3ff));
428
441
  blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
429
442
  blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
430
443
  blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
431
444
  blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
445
+ } else {
446
+ // unpaired surrogate: U+FFFD
447
+ blocks[i >>> 2] |= 0xef << SHIFT[i++ & 3];
448
+ blocks[i >>> 2] |= 0xbf << SHIFT[i++ & 3];
449
+ blocks[i >>> 2] |= 0xbd << SHIFT[i++ & 3];
432
450
  }
433
451
  }
434
452
  }
@@ -811,7 +829,7 @@
811
829
  var i, result = formatMessage(key);
812
830
  key = result[0];
813
831
  if (result[1]) {
814
- var bytes = [], length = key.length, index = 0, code;
832
+ var bytes = [], length = key.length, index = 0, code, code2;
815
833
  for (i = 0; i < length; ++i) {
816
834
  code = key.charCodeAt(i);
817
835
  if (code < 0x80) {
@@ -823,12 +841,18 @@
823
841
  bytes[index++] = (0xe0 | (code >>> 12));
824
842
  bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
825
843
  bytes[index++] = (0x80 | (code & 0x3f));
826
- } else {
827
- code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
844
+ } else if (code < 0xdc00 && (code2 = key.charCodeAt(i + 1)) >= 0xdc00 && code2 < 0xe000) {
845
+ ++i;
846
+ code = 0x10000 + (((code & 0x3ff) << 10) | (code2 & 0x3ff));
828
847
  bytes[index++] = (0xf0 | (code >>> 18));
829
848
  bytes[index++] = (0x80 | ((code >>> 12) & 0x3f));
830
849
  bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
831
850
  bytes[index++] = (0x80 | (code & 0x3f));
851
+ } else {
852
+ // unpaired surrogate: U+FFFD
853
+ bytes[index++] = 0xef;
854
+ bytes[index++] = 0xbf;
855
+ bytes[index++] = 0xbd;
832
856
  }
833
857
  }
834
858
  key = bytes;