Skip to content

Commit

Permalink
Merge branch 'masq-insense'
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Jan 10, 2019
2 parents 324c409 + 995fcab commit f82a727
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
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).


### [8.21.0] - 2019-01-10
- 'To Case Insensitive Regex' and 'From Case Insensitive Regex' operations added [@masq] | [#461]

### [8.20.0] - 2019-01-09
- 'Generate Lorem Ipsum' operation added [@klaxon1] | [#455]

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



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

[#95]: https://github.com/gchq/CyberChef/pull/299
[#173]: https://github.com/gchq/CyberChef/pull/173
Expand Down Expand Up @@ -165,3 +170,4 @@ All major and minor version changes will be documented in this file. Details of
[#449]: https://github.com/gchq/CyberChef/pull/449
[#455]: https://github.com/gchq/CyberChef/pull/455
[#458]: https://github.com/gchq/CyberChef/pull/458
[#461]: https://github.com/gchq/CyberChef/pull/461
2 changes: 2 additions & 0 deletions src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@
"Remove null bytes",
"To Upper case",
"To Lower case",
"To Case Insensitive Regex",
"From Case Insensitive Regex",
"Add line numbers",
"Remove line numbers",
"To Table",
Expand Down
39 changes: 39 additions & 0 deletions src/core/operations/FromCaseInsensitiveRegex.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @author masq [github.cyberchef@masq.cc]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/

import Operation from "../Operation";

/**
* From Case Insensitive Regex operation
*/
class FromCaseInsensitiveRegex extends Operation {

/**
* FromCaseInsensitiveRegex constructor
*/
constructor() {
super();

this.name = "From Case Insensitive Regex";
this.module = "Default";
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>";
this.infoURL = "https://wikipedia.org/wiki/Regular_expression";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}

/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
return input.replace(/\[[a-z]{2}\]/ig, m => m[1].toUpperCase() === m[2].toUpperCase() ? m[1] : m);
}
}

export default FromCaseInsensitiveRegex;
39 changes: 39 additions & 0 deletions src/core/operations/ToCaseInsensitiveRegex.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @author masq [github.cyberchef@masq.cc]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/

import Operation from "../Operation";

/**
* To Case Insensitive Regex operation
*/
class ToCaseInsensitiveRegex extends Operation {

/**
* ToCaseInsensitiveRegex constructor
*/
constructor() {
super();

this.name = "To Case Insensitive Regex";
this.module = "Default";
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>";
this.infoURL = "https://wikipedia.org/wiki/Regular_expression";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}

/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
return input.replace(/[a-z]/ig, m => `[${m.toLowerCase()}${m.toUpperCase()}]`);
}
}

export default ToCaseInsensitiveRegex;
1 change: 1 addition & 0 deletions tests/operations/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import "./tests/TranslateDateTimeFormat";
import "./tests/Magic";
import "./tests/ParseTLV";
import "./tests/Media";
import "./tests/ToFromInsensitiveRegex";

// Cannot test operations that use the File type yet
//import "./tests/SplitColourChannels";
Expand Down
56 changes: 56 additions & 0 deletions tests/operations/tests/ToFromInsensitiveRegex.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* To/From Case Insensitive Regex tests.
*
* @author masq [github.cyberchef@masq.cc]
*
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";

TestRegister.addTests([
{
name: "To Case Insensitive Regex: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "To Case Insensitive Regex",
args: [],
},
],
},
{
name: "From Case Insensitive Regex: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "From Case Insensitive Regex",
args: [],
},
],
},
{
name: "To Case Insensitive Regex: simple test",
input: "S0meth!ng",
expectedOutput: "[sS]0[mM][eE][tT][hH]![nN][gG]",
recipeConfig: [
{
op: "To Case Insensitive Regex",
args: [],
},
],
},
{
name: "From Case Insensitive Regex: simple test",
input: "[sS]0[mM][eE][tT][hH]![nN][Gg] [wr][On][g]?",
expectedOutput: "s0meth!nG [wr][On][g]?",
recipeConfig: [
{
op: "From Case Insensitive Regex",
args: [],
},
],
},
]);

0 comments on commit f82a727

Please sign in to comment.