Fixed tests for octal operations.

This commit is contained in:
n1474335 2017-04-05 22:00:06 +01:00
parent a36c9ca339
commit 5f85bff315
5 changed files with 88 additions and 7 deletions

View file

@ -212,7 +212,7 @@ const Utils = {
* @returns {string}
*/
printable: function(str, preserveWs) {
if (window && window.app && !window.app.options.treatAsUtf8) {
if (typeof window !== "undefined" && window.app && !window.app.options.treatAsUtf8) {
str = Utils.byteArrayToChars(Utils.strToByteArray(str));
}
@ -388,8 +388,9 @@ const Utils = {
var wordArray = CryptoJS.enc.Utf8.parse(str),
byteArray = Utils.wordArrayToByteArray(wordArray);
if (window && str.length !== wordArray.sigBytes)
if (typeof window !== "undefined" && str.length !== wordArray.sigBytes) {
window.app.options.attemptHighlight = false;
}
return byteArray;
},
@ -440,7 +441,7 @@ const Utils = {
var wordArray = new CryptoJS.lib.WordArray.init(words, byteArray.length),
str = CryptoJS.enc.Utf8.stringify(wordArray);
if (window && str.length !== wordArray.sigBytes)
if (typeof window !== "undefined" && str.length !== wordArray.sigBytes)
window.app.options.attemptHighlight = false;
return str;
} catch (err) {

View file

@ -455,7 +455,7 @@ const OperationConfig = {
]
},
"From Octal": {
description: "Converts a octal byte string back into its raw value.<br><br>e.g. <code>316 223 316 265 316 271 316 254 40 317 203 316 277 317 205</code> becomes the UTF-8 encoded string <code>Γειά σου</code>",
description: "Converts an octal byte string back into its raw value.<br><br>e.g. <code>316 223 316 265 316 271 316 254 40 317 203 316 277 317 205</code> becomes the UTF-8 encoded string <code>Γειά σου</code>",
run: ByteRepr.runFromOct,
highlight: false,
highlightReverse: false,

View file

@ -56,7 +56,7 @@ const ByteRepr = {
/**
* To Oct operation.
* To Octal operation.
*
* @author Matt C [matt@artemisbot.pw]
* @param {byteArray} input
@ -65,11 +65,12 @@ const ByteRepr = {
*/
runToOct: function(input, args) {
var delim = Utils.charRep[args[0] || "Space"];
return input.map(val => parseInt(Utils.bin(val), 2).toString(8)).join(delim);
return input.map(val => val.toString(8)).join(delim);
},
/**
* From Oct operation.
* From Octal operation.
*
* @author Matt C [matt@artemisbot.pw]
* @param {string} input
@ -82,6 +83,7 @@ const ByteRepr = {
return input.split(delim).map(val => parseInt(val, 8));
},
/**
* @constant
* @default