mirror of
https://github.com/emn178/js-md5.git
synced 2026-11-18 16:08:52 +08:00
### Fixed
- Incorrect hash for `DataView` input. - Throws `ArrayBuffer is not defined` in browsers without `ArrayBuffer`. ### Changed - Multi-byte typed arrays such as `Uint16Array`, `Uint32Array` and `Float32Array` are now hashed by their underlying bytes, the same as Node.js `crypto` and Web Crypto. Previously each element was treated as one byte. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c2a7870840
commit
66db5dbd99
+10
-4
@@ -13,7 +13,7 @@ var md5$1 = {exports: {}};
|
||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||
*
|
||||
* @namespace md5
|
||||
* @version 0.10.0
|
||||
* @version 0.11.0
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2014-2026
|
||||
* @license MIT
|
||||
@@ -51,7 +51,7 @@ var md5$1 = {exports: {}};
|
||||
|
||||
var isArray = Array.isArray;
|
||||
|
||||
var isView = ArrayBuffer.isView;
|
||||
var isView = ArrayBuffer.isView ;
|
||||
|
||||
// [message: string, isString: bool]
|
||||
var formatMessage = function (message) {
|
||||
@@ -65,10 +65,14 @@ var md5$1 = {exports: {}};
|
||||
if (message.constructor === ArrayBuffer) {
|
||||
return [new Uint8Array(message), false];
|
||||
}
|
||||
if (!isArray(message) && !isView(message)) {
|
||||
if (isArray(message)) {
|
||||
return [message, false];
|
||||
}
|
||||
if (!isView(message)) {
|
||||
throw new Error(INPUT_ERROR);
|
||||
}
|
||||
return [message, false];
|
||||
// read the underlying bytes of any view (DataView, Uint16Array, ...)
|
||||
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -184,6 +188,8 @@ var md5$1 = {exports: {}};
|
||||
throw new Error(INPUT_ERROR);
|
||||
} else if (message.constructor === ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
} else if (isView(message) && message.constructor !== Buffer) {
|
||||
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
||||
}
|
||||
}
|
||||
if (isArray(message) || isView(message) ||
|
||||
|
||||
Reference in New Issue
Block a user