mirror of
https://github.com/emn178/js-md5.git
synced 2026-08-12 20:31:43 +08:00
* Fixed ArrayBuffer.isView issue in IE10.
* Improved performance of input check.
This commit is contained in:
+23
-15
@@ -2,7 +2,7 @@
|
||||
* [js-md5]{@link https://github.com/emn178/js-md5}
|
||||
*
|
||||
* @namespace md5
|
||||
* @version 0.6.0
|
||||
* @version 0.6.1
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2014-2017
|
||||
* @license MIT
|
||||
@@ -45,6 +45,12 @@
|
||||
};
|
||||
}
|
||||
|
||||
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
|
||||
ArrayBuffer.isView = function (obj) {
|
||||
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @method hex
|
||||
* @memberof md5
|
||||
@@ -210,23 +216,25 @@
|
||||
if (this.finalized) {
|
||||
return;
|
||||
}
|
||||
var notString = typeof(message) != 'string';
|
||||
if (notString) {
|
||||
if (message === null || message === undefined) {
|
||||
throw ERROR;
|
||||
} else if (message.constructor === root.ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
}
|
||||
}
|
||||
var length = message.length;
|
||||
if (notString) {
|
||||
if (typeof length !== 'number' ||
|
||||
!Array.isArray(message) &&
|
||||
!(ARRAY_BUFFER && ArrayBuffer.isView(message))) {
|
||||
|
||||
var notString, type = typeof message;
|
||||
if (type !== 'string') {
|
||||
if (type === 'object') {
|
||||
if (message === null) {
|
||||
throw ERROR;
|
||||
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
} else if (!Array.isArray(message)) {
|
||||
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
||||
throw ERROR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw ERROR;
|
||||
}
|
||||
notString = true;
|
||||
}
|
||||
var code, index = 0, i, blocks = this.blocks;
|
||||
var code, index = 0, i, length = message.length, blocks = this.blocks;
|
||||
var buffer8 = this.buffer8;
|
||||
|
||||
while (index < length) {
|
||||
|
||||
Reference in New Issue
Block a user