mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Fix for UTF-8/binary handling in hashing operations. Added tests to prevent future breakages. Closes #249.
This commit is contained in:
parent
8360c9e9f9
commit
f47a408755
4 changed files with 339 additions and 69 deletions
|
@ -495,15 +495,16 @@ const Utils = {
|
|||
* Converts an ArrayBuffer to a string.
|
||||
*
|
||||
* @param {ArrayBuffer} arrayBuffer
|
||||
* @param {boolean} [utf8=true] - Whether to attempt to decode the buffer as UTF-8
|
||||
* @returns {string}
|
||||
*
|
||||
* @example
|
||||
* // returns "hello"
|
||||
* Utils.arrayBufferToStr(Uint8Array.from([104,101,108,108,111]).buffer);
|
||||
*/
|
||||
arrayBufferToStr: function(arrayBuffer) {
|
||||
arrayBufferToStr: function(arrayBuffer, utf8=true) {
|
||||
const byteArray = Array.prototype.slice.call(new Uint8Array(arrayBuffer));
|
||||
return Utils.byteArrayToUtf8(byteArray);
|
||||
return utf8 ? Utils.byteArrayToUtf8(byteArray) : Utils.byteArrayToChars(byteArray);
|
||||
},
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue