Skip to content

Commit 972ec23

Browse files
Differentially test linear-time regexp support for BusyBox
Create a unit test that differentially tests the change in BusyBox escaping from "normal" regular expression to linear-time-based regular expressions (in [1]). The (updates to the) `2410.patch` file accounts for a later bug fix (see [2]). [1]: e582b3e [2]: 6add105
1 parent b058ad2 commit 972ec23

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ jobs:
364364
git config --global user.name "John Doe"
365365
git config --global user.email johndoe@example.com
366366
git commit -m 'n/a'
367-
git apply ../../bash.patch
367+
git apply ../../2410.patch
368368
- name: Run unit tests
369369
run: npm run coverage:unit
370370
transpile:

bash.patch renamed to 2410.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ index 19fba6d..c1c57ce 100644
1111
.replace(/(?<=[:=])(~)(?=[\s+\-/0:=]|$)/gu, "\\$1")
1212
.replace(/([\t ])/gu, "\\$1");
1313
}
14+
diff --git a/src/internal/unix/busybox.js b/src/internal/unix/busybox.js
15+
index e61262f..0c91dc4 100644
16+
--- a/src/internal/unix/busybox.js
17+
+++ b/src/internal/unix/busybox.js
18+
@@ -15,7 +15,7 @@ function escapeArg(arg) {
19+
.replace(/\n/gu, " ")
20+
.replace(/\\/gu, "\\\\")
21+
.replace(/(?<=^|\s)([#~])/gu, "\\$1")
22+
- .replace(/(["$&'()*;<>?`|])/gu, "\\$1")
23+
+ .replace(/(["$&'()*;<>?`|[\]])/gu, "\\$1")
24+
.replace(/([\t ])/gu, "\\$1");
25+
}
26+

test/unit/unix/bash.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @overview Contains differential tests for the migration form standard regular
3-
* expressions to linear-time regular expressions in Bash.
2+
* @overview Contains (additional) unit tests for the escaping functionality for
3+
* the Bourne-again shell (Bash).
44
* @license MIT
55
*/
66

test/unit/unix/busybox.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @overview Contains (additional) unit tests for the escaping functionality for
3+
* the BusyBox shell.
4+
* @license MIT
5+
*/
6+
7+
import { testProp } from "@fast-check/ava";
8+
import * as fc from "fast-check";
9+
10+
import * as old from "../../../node_modules/shescape-previous/src/internal/unix/busybox.js";
11+
import * as upd from "../../../src/internal/unix/busybox.js";
12+
13+
const numRuns = 5_000_000;
14+
15+
testProp(
16+
"escape functionality is unchanged",
17+
[fc.string()],
18+
(t, arg) => {
19+
const updFn = upd.getEscapeFunction();
20+
const oldFn = old.getEscapeFunction();
21+
22+
const got = updFn(arg);
23+
const want = oldFn(arg);
24+
t.is(got, want);
25+
},
26+
{ numRuns },
27+
);
28+
29+
testProp(
30+
"quote functionality is unchanged",
31+
[fc.string()],
32+
(t, arg) => {
33+
const updFn = upd.getQuoteFunction();
34+
const oldFn = old.getQuoteFunction();
35+
36+
const got = updFn[0](updFn[1](arg));
37+
const want = oldFn[0](oldFn[1](arg));
38+
t.is(got, want);
39+
},
40+
{ numRuns },
41+
);
42+
43+
testProp(
44+
"flag protection functionality is unchanged",
45+
[fc.string()],
46+
(t, arg) => {
47+
const updFn = upd.getFlagProtectionFunction();
48+
const oldFn = old.getFlagProtectionFunction();
49+
50+
const got = updFn(arg);
51+
const want = oldFn(arg);
52+
t.is(got, want);
53+
},
54+
{ numRuns },
55+
);

test/unit/win/cmd.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @overview Contains differential tests for the migration form standard regular
3-
* expressions to linear-time regular expressions in CMD.
2+
* @overview Contains (additional) unit tests for the escaping functionality for
3+
* the the Windows Command Prompt.
44
* @license MIT
55
*/
66

0 commit comments

Comments
 (0)