Skip to content

Commit ff2d661

Browse files
Align Stubscape behavior for illegal arguments with Shescape (#2382)
1 parent 5f9269a commit ff2d661

3 files changed

Lines changed: 39 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Versioning].
1010
## [Unreleased]
1111

1212
- Expand support for `--enable-experimental-regexp-engine`. ([#2358])
13-
- Improve rejecting non-array inputs to `escapeAll` & `quoteAll`. ([#2363])
13+
- Improve rejecting non-array inputs to `escapeAll` & `quoteAll`. ([#2363],
14+
[#2382])
1415

1516
## [2.1.8] - 2026-01-25
1617

@@ -383,6 +384,7 @@ Versioning].
383384
[#2342]: https://github.com/ericcornelissen/shescape/pull/2342
384385
[#2358]: https://github.com/ericcornelissen/shescape/pull/2358
385386
[#2363]: https://github.com/ericcornelissen/shescape/pull/2363
387+
[#2382]: https://github.com/ericcornelissen/shescape/pull/2382
386388
[552e8ea]: https://github.com/ericcornelissen/shescape/commit/552e8eab56861720b1d4e5474fb65741643358f9
387389
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
388390
[semantic versioning]: https://semver.org/spec/v2.0.0.html

src/testing.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @license MPL-2.0
44
*/
55

6-
import { checkedToString } from "./internal/reflection.js";
6+
import { checkedToString, ensureArray } from "./internal/reflection.js";
77

88
/**
99
* A list of example shell injection strings to test whether or not a function
@@ -68,6 +68,7 @@ export class Stubscape {
6868
}
6969

7070
escapeAll(args) {
71+
ensureArray(args);
7172
return args.map((arg) => this.escape(arg));
7273
}
7374

@@ -80,6 +81,7 @@ export class Stubscape {
8081
}
8182

8283
quoteAll(args) {
84+
ensureArray(args);
8385
return args.map((arg) => this.quote(arg));
8486
}
8587
}

test/integration/testing/functional.test.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Throwscape,
1616
} from "shescape/testing";
1717

18-
import { arbitrary } from "../_.js";
18+
import { arbitrary, constants } from "../_.js";
1919

2020
test("injection strings", (t) => {
2121
t.true(Array.isArray(injectionStrings));
@@ -77,7 +77,13 @@ testProp(
7777

7878
testProp(
7979
"Stubscape#escape (stubscape =~ shescape)",
80-
[fc.anything(), arbitrary.shescapeOptions()],
80+
[
81+
fc.oneof(
82+
fc.anything(),
83+
fc.constantFrom(...constants.illegalArguments.map((arg) => arg.value)),
84+
),
85+
arbitrary.shescapeOptions(),
86+
],
8187
(t, arg, options) => {
8288
let result, stubResult, errored, stubErrored;
8389

@@ -109,7 +115,15 @@ testProp(
109115

110116
testProp(
111117
"Stubscape#escapeAll (stubscape =~ shescape)",
112-
[fc.anything(), arbitrary.shescapeOptions()],
118+
[
119+
fc.oneof(
120+
fc.anything(),
121+
fc.constantFrom(
122+
...constants.illegalArgumentLists.map((args) => args.value),
123+
),
124+
),
125+
arbitrary.shescapeOptions(),
126+
],
113127
(t, args, options) => {
114128
let result, stubResult, errored, stubErrored;
115129

@@ -141,7 +155,13 @@ testProp(
141155

142156
testProp(
143157
"Stubscape#quote, with shell (stubscape =~ shescape)",
144-
[fc.anything(), arbitrary.shescapeOptions()],
158+
[
159+
fc.oneof(
160+
fc.anything(),
161+
fc.constantFrom(...constants.illegalArguments.map((arg) => arg.value)),
162+
),
163+
arbitrary.shescapeOptions(),
164+
],
145165
(t, arg, options) => {
146166
let result, stubResult, errored, stubErrored;
147167

@@ -185,7 +205,15 @@ test("stubscape#quote with shell set to false", (t) => {
185205

186206
testProp(
187207
"Stubscape#quoteAll, with shell (stubscape =~ shescape)",
188-
[fc.anything(), arbitrary.shescapeOptions()],
208+
[
209+
fc.oneof(
210+
fc.anything(),
211+
fc.constantFrom(
212+
...constants.illegalArgumentLists.map((args) => args.value),
213+
),
214+
),
215+
arbitrary.shescapeOptions(),
216+
],
189217
(t, args, options) => {
190218
let result, stubResult, errored, stubErrored;
191219

0 commit comments

Comments
 (0)