From 179eb9a379e64d2bbb7d4323e62a2fdca21e044a Mon Sep 17 00:00:00 2001 From: Kirill Date: Fri, 3 Jul 2026 13:06:55 +0300 Subject: [PATCH] Validate Wrap line width (#2606) Co-authored-by: GCHQDeveloper581 <63102987+GCHQDeveloper581@users.noreply.github.com> Co-authored-by: C85297 <95289555+C85297@users.noreply.github.com> --- src/core/operations/Wrap.mjs | 5 ++++ tests/operations/tests/Wrap.mjs | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/core/operations/Wrap.mjs b/src/core/operations/Wrap.mjs index c6e57f88..004246ac 100644 --- a/src/core/operations/Wrap.mjs +++ b/src/core/operations/Wrap.mjs @@ -6,6 +6,8 @@ import Operation from "../Operation.mjs"; +const MAX_LINE_WIDTH = 65536; + /** * Wrap operation */ @@ -27,6 +29,9 @@ class Wrap extends Operation { "name": "Line Width", "type": "number", "value": 64, + "min": 1, + "max": MAX_LINE_WIDTH, + "integer": true, }, ]; } diff --git a/tests/operations/tests/Wrap.mjs b/tests/operations/tests/Wrap.mjs index 8d7c9a51..b7569ba8 100644 --- a/tests/operations/tests/Wrap.mjs +++ b/tests/operations/tests/Wrap.mjs @@ -40,5 +40,49 @@ TestRegister.addTests([ "args": [10] }, ], + }, + { + name: "Wrap rejects zero line width", + input: "hello", + expectedOutput: "Line Width must be greater than or equal to 1.", + recipeConfig: [ + { + "op": "Wrap", + "args": [0] + }, + ], + }, + { + name: "Wrap rejects negative line width", + input: "hello", + expectedOutput: "Line Width must be greater than or equal to 1.", + recipeConfig: [ + { + "op": "Wrap", + "args": [-1] + }, + ], + }, + { + name: "Wrap rejects non-integer line width", + input: "hello", + expectedOutput: "Line Width must be an integer.", + recipeConfig: [ + { + "op": "Wrap", + "args": [1.1] + }, + ], + }, + { + name: "Wrap rejects excessive line width", + input: "hello", + expectedOutput: "Line Width must be less than or equal to 65536.", + recipeConfig: [ + { + "op": "Wrap", + "args": [65537] + }, + ], } ]);