fix: validate text encoding options (#2497)
This commit is contained in:
parent
3034d63f90
commit
20b46bf1a0
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import cptable from "codepage";
|
import cptable from "codepage";
|
||||||
import {CHR_ENC_CODE_PAGES} from "../lib/ChrEnc.mjs";
|
import {CHR_ENC_CODE_PAGES} from "../lib/ChrEnc.mjs";
|
||||||
|
|
||||||
@ -48,6 +49,9 @@ class DecodeText extends Operation {
|
|||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const format = CHR_ENC_CODE_PAGES[args[0]];
|
const format = CHR_ENC_CODE_PAGES[args[0]];
|
||||||
|
if (!format) {
|
||||||
|
throw new OperationError("Invalid encoding");
|
||||||
|
}
|
||||||
return cptable.utils.decode(format, new Uint8Array(input));
|
return cptable.utils.decode(format, new Uint8Array(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import cptable from "codepage";
|
import cptable from "codepage";
|
||||||
import {CHR_ENC_CODE_PAGES} from "../lib/ChrEnc.mjs";
|
import {CHR_ENC_CODE_PAGES} from "../lib/ChrEnc.mjs";
|
||||||
|
|
||||||
@ -48,6 +49,9 @@ class EncodeText extends Operation {
|
|||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const format = CHR_ENC_CODE_PAGES[args[0]];
|
const format = CHR_ENC_CODE_PAGES[args[0]];
|
||||||
|
if (!format) {
|
||||||
|
throw new OperationError("Invalid encoding");
|
||||||
|
}
|
||||||
const encoded = cptable.utils.encode(format, input);
|
const encoded = cptable.utils.encode(format, input);
|
||||||
return new Uint8Array(encoded).buffer;
|
return new Uint8Array(encoded).buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,6 +68,32 @@ TestRegister.addTests([
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Encode text: empty encoding",
|
||||||
|
input: "hello",
|
||||||
|
expectedOutput: "Invalid encoding",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Encode text",
|
||||||
|
"args": [""]
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Decode text: empty encoding",
|
||||||
|
input: "68 65 6c 6c 6f",
|
||||||
|
expectedOutput: "Invalid encoding",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "From Hex",
|
||||||
|
"args": ["Space"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "Decode text",
|
||||||
|
"args": [""]
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Generate Base64 Windows PowerShell",
|
name: "Generate Base64 Windows PowerShell",
|
||||||
input: "ZABpAHIAIAAiAGMAOgBcAHAAcgBvAGcAcgBhAG0AIABmAGkAbABlAHMAIgAgAA==",
|
input: "ZABpAHIAIAAiAGMAOgBcAHAAcgBvAGcAcgBhAG0AIABmAGkAbABlAHMAIgAgAA==",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user