You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 34f0eaf
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/scriptlets/trusted-replace-argument.ts
+28-12Lines changed: 28 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,9 @@ import { type Source } from './scriptlets';
48
48
* - `argumentValue` – required, string value to set for the argument.
49
49
* If it starts with `replace:`, it is treated as a replacement pattern in the format `replace:/regex/replacement/`.
50
50
* To replace all occurrences of a pattern, the replacement string must include the global flag `g`, like this: `replace:/foo/bar/g`, otherwise only the first occurrence will be replaced.
51
+
* If the matched argument is not a string, it is converted to a string before applying the replacement,
52
+
* and the argument is modified only when the replacement changes the resulting value;
53
+
* otherwise the original value and its type are kept.
51
54
* If it starts with `json:`, it is treated as a JSON string to parse and set for the argument. For example, `json:{"key": "value"}` will set the argument to an object `{ key: 'value' }`.
52
55
* If it does not start with `replace:` or `json:`, it is treated as a constant value to set for the argument, or as one of the following predefined constants:
53
56
* - `undefined`
@@ -325,6 +328,29 @@ export function trustedReplaceArgument(
325
328
returntrue;
326
329
};
327
330
331
+
/**
332
+
* Replaces the argument at the target index in the provided arguments list.
333
+
*
334
+
* In `replace:` mode the argument is converted to a string and the regex replacement
335
+
* is applied; the result is assigned only if it differs from the converted value,
336
+
* so arguments that do not match the regex keep their original value and type
337
+
* (e.g. numbers). Otherwise the argument is set to the constant value.
338
+
*
339
+
* @param argumentsList - The arguments list to modify in place.
0 commit comments