fix: restrict A1Z26 magic checks to valid ranges

This commit is contained in:
Кирилл Ветров 2026-07-05 23:25:57 +03:00
parent 002ed911b1
commit d8dbd32cd8
2 changed files with 50 additions and 6 deletions

View File

@ -35,32 +35,32 @@ class A1Z26CipherDecode extends Operation {
];
this.checks = [
{
pattern: "^\\s*([12]?[0-9] )+[12]?[0-9]\\s*$",
pattern: "^\\s*((?:0?[1-9]|1[0-9]|2[0-6]) )+(?:0?[1-9]|1[0-9]|2[0-6])\\s*$",
flags: "",
args: ["Space"]
},
{
pattern: "^\\s*([12]?[0-9],)+[12]?[0-9]\\s*$",
pattern: "^\\s*((?:0?[1-9]|1[0-9]|2[0-6]),)+(?:0?[1-9]|1[0-9]|2[0-6])\\s*$",
flags: "",
args: ["Comma"]
},
{
pattern: "^\\s*([12]?[0-9];)+[12]?[0-9]\\s*$",
pattern: "^\\s*((?:0?[1-9]|1[0-9]|2[0-6]);)+(?:0?[1-9]|1[0-9]|2[0-6])\\s*$",
flags: "",
args: ["Semi-colon"]
},
{
pattern: "^\\s*([12]?[0-9]:)+[12]?[0-9]\\s*$",
pattern: "^\\s*((?:0?[1-9]|1[0-9]|2[0-6]):)+(?:0?[1-9]|1[0-9]|2[0-6])\\s*$",
flags: "",
args: ["Colon"]
},
{
pattern: "^\\s*([12]?[0-9]\\n)+[12]?[0-9]\\s*$",
pattern: "^\\s*((?:0?[1-9]|1[0-9]|2[0-6])\\n)+(?:0?[1-9]|1[0-9]|2[0-6])\\s*$",
flags: "",
args: ["Line feed"]
},
{
pattern: "^\\s*([12]?[0-9]\\r\\n)+[12]?[0-9]\\s*$",
pattern: "^\\s*((?:0?[1-9]|1[0-9]|2[0-6])\\r\\n)+(?:0?[1-9]|1[0-9]|2[0-6])\\s*$",
flags: "",
args: ["CRLF"]
}

View File

@ -152,5 +152,49 @@ TestRegister.addTests([
args: [1, false, false]
}
]
},
{
name: "Magic: invalid zero A1Z26 values do not match",
input: "0,0",
unexpectedMatch: /A1Z26 Cipher Decode/,
recipeConfig: [
{
op: "Magic",
args: [0, false, false]
}
]
},
{
name: "Magic: invalid high A1Z26 values do not match",
input: "27,1",
unexpectedMatch: /A1Z26 Cipher Decode/,
recipeConfig: [
{
op: "Magic",
args: [0, false, false]
}
]
},
{
name: "Magic: valid leading-zero A1Z26 values match",
input: "26,01",
expectedMatch: /A1Z26 Cipher Decode/,
recipeConfig: [
{
op: "Magic",
args: [0, false, false]
}
]
},
{
name: "Magic: valid leading-zero A1Z26 values match with two digits",
input: "09,10",
expectedMatch: /A1Z26 Cipher Decode/,
recipeConfig: [
{
op: "Magic",
args: [0, false, false]
}
]
}
]);