Skip to content

Commit f82a727

Browse files
committed
Merge branch 'masq-insense'
2 parents 324c409 + 995fcab commit f82a727

File tree

6 files changed

+143
-0
lines changed

6 files changed

+143
-0
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
All major and minor version changes will be documented in this file. Details of patch-level version changes can be found in [commit messages](https://github.com/gchq/CyberChef/commits/master).
33

44

5+
### [8.21.0] - 2019-01-10
6+
- 'To Case Insensitive Regex' and 'From Case Insensitive Regex' operations added [@masq] | [#461]
7+
58
### [8.20.0] - 2019-01-09
69
- 'Generate Lorem Ipsum' operation added [@klaxon1] | [#455]
710

@@ -91,6 +94,7 @@ All major and minor version changes will be documented in this file. Details of
9194

9295

9396

97+
[8.21.0]: https://github.com/gchq/CyberChef/releases/tag/v8.21.0
9498
[8.20.0]: https://github.com/gchq/CyberChef/releases/tag/v8.20.0
9599
[8.19.0]: https://github.com/gchq/CyberChef/releases/tag/v8.19.0
96100
[8.18.0]: https://github.com/gchq/CyberChef/releases/tag/v8.18.0
@@ -134,6 +138,7 @@ All major and minor version changes will be documented in this file. Details of
134138
[@tcode2k16]: https://github.com/tcode2k16
135139
[@Cynser]: https://github.com/Cynser
136140
[@anthony-arnold]: https://github.com/anthony-arnold
141+
[@masq]: https://github.com/masq
137142

138143
[#95]: https://github.com/gchq/CyberChef/pull/299
139144
[#173]: https://github.com/gchq/CyberChef/pull/173
@@ -165,3 +170,4 @@ All major and minor version changes will be documented in this file. Details of
165170
[#449]: https://github.com/gchq/CyberChef/pull/449
166171
[#455]: https://github.com/gchq/CyberChef/pull/455
167172
[#458]: https://github.com/gchq/CyberChef/pull/458
173+
[#461]: https://github.com/gchq/CyberChef/pull/461

src/core/config/Categories.json

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@
189189
"Remove null bytes",
190190
"To Upper case",
191191
"To Lower case",
192+
"To Case Insensitive Regex",
193+
"From Case Insensitive Regex",
192194
"Add line numbers",
193195
"Remove line numbers",
194196
"To Table",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @author masq [[email protected]]
3+
* @copyright Crown Copyright 2018
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation";
8+
9+
/**
10+
* From Case Insensitive Regex operation
11+
*/
12+
class FromCaseInsensitiveRegex extends Operation {
13+
14+
/**
15+
* FromCaseInsensitiveRegex constructor
16+
*/
17+
constructor() {
18+
super();
19+
20+
this.name = "From Case Insensitive Regex";
21+
this.module = "Default";
22+
this.description = "Converts a case-insensitive regex string to a case sensitive regex string (no guarantee on it being the proper original casing) in case the i flag wasn't available at the time but now is, or you need it to be case-sensitive again.<br><br>e.g. <code>[mM][oO][zZ][iI][lL][lL][aA]/[0-9].[0-9] .*</code> becomes <code>Mozilla/[0-9].[0-9] .*</code>";
23+
this.infoURL = "https://wikipedia.org/wiki/Regular_expression";
24+
this.inputType = "string";
25+
this.outputType = "string";
26+
this.args = [];
27+
}
28+
29+
/**
30+
* @param {string} input
31+
* @param {Object[]} args
32+
* @returns {string}
33+
*/
34+
run(input, args) {
35+
return input.replace(/\[[a-z]{2}\]/ig, m => m[1].toUpperCase() === m[2].toUpperCase() ? m[1] : m);
36+
}
37+
}
38+
39+
export default FromCaseInsensitiveRegex;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @author masq [[email protected]]
3+
* @copyright Crown Copyright 2018
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation";
8+
9+
/**
10+
* To Case Insensitive Regex operation
11+
*/
12+
class ToCaseInsensitiveRegex extends Operation {
13+
14+
/**
15+
* ToCaseInsensitiveRegex constructor
16+
*/
17+
constructor() {
18+
super();
19+
20+
this.name = "To Case Insensitive Regex";
21+
this.module = "Default";
22+
this.description = "Converts a case-sensitive regex string into a case-insensitive regex string in case the i flag is unavailable to you.<br><br>e.g. <code>Mozilla/[0-9].[0-9] .*</code> becomes <code>[mM][oO][zZ][iI][lL][lL][aA]/[0-9].[0-9] .*</code>";
23+
this.infoURL = "https://wikipedia.org/wiki/Regular_expression";
24+
this.inputType = "string";
25+
this.outputType = "string";
26+
this.args = [];
27+
}
28+
29+
/**
30+
* @param {string} input
31+
* @param {Object[]} args
32+
* @returns {string}
33+
*/
34+
run(input, args) {
35+
return input.replace(/[a-z]/ig, m => `[${m.toLowerCase()}${m.toUpperCase()}]`);
36+
}
37+
}
38+
39+
export default ToCaseInsensitiveRegex;

tests/operations/index.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import "./tests/TranslateDateTimeFormat";
8282
import "./tests/Magic";
8383
import "./tests/ParseTLV";
8484
import "./tests/Media";
85+
import "./tests/ToFromInsensitiveRegex";
8586

8687
// Cannot test operations that use the File type yet
8788
//import "./tests/SplitColourChannels";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* To/From Case Insensitive Regex tests.
3+
*
4+
* @author masq [[email protected]]
5+
*
6+
* @copyright Crown Copyright 2018
7+
* @license Apache-2.0
8+
*/
9+
import TestRegister from "../TestRegister";
10+
11+
TestRegister.addTests([
12+
{
13+
name: "To Case Insensitive Regex: nothing",
14+
input: "",
15+
expectedOutput: "",
16+
recipeConfig: [
17+
{
18+
op: "To Case Insensitive Regex",
19+
args: [],
20+
},
21+
],
22+
},
23+
{
24+
name: "From Case Insensitive Regex: nothing",
25+
input: "",
26+
expectedOutput: "",
27+
recipeConfig: [
28+
{
29+
op: "From Case Insensitive Regex",
30+
args: [],
31+
},
32+
],
33+
},
34+
{
35+
name: "To Case Insensitive Regex: simple test",
36+
input: "S0meth!ng",
37+
expectedOutput: "[sS]0[mM][eE][tT][hH]![nN][gG]",
38+
recipeConfig: [
39+
{
40+
op: "To Case Insensitive Regex",
41+
args: [],
42+
},
43+
],
44+
},
45+
{
46+
name: "From Case Insensitive Regex: simple test",
47+
input: "[sS]0[mM][eE][tT][hH]![nN][Gg] [wr][On][g]?",
48+
expectedOutput: "s0meth!nG [wr][On][g]?",
49+
recipeConfig: [
50+
{
51+
op: "From Case Insensitive Regex",
52+
args: [],
53+
},
54+
],
55+
},
56+
]);

0 commit comments

Comments
 (0)