@workover/cli 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib.mjs +18 -2
- package/package.json +1 -1
package/lib.mjs
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
// Pure helpers for the Workover CLI, split out so they can be unit-tested without importing
|
|
2
2
|
// bin/workover.mjs (which runs a command + calls process.exit on load).
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Strip trailing slashes from the API base URL (so `${API}${path}` never doubles up).
|
|
6
|
+
*
|
|
7
|
+
* A LOOP, not `/\/+$/`. That pattern is quadratic when the anchor fails — the engine matches the
|
|
8
|
+
* run of slashes from every starting position before discovering there is no end-of-string. On a
|
|
9
|
+
* run of '/' followed by one other character, measured: 10k chars 30ms, 50k chars 747ms, 200k chars
|
|
10
|
+
* 12,008ms. Five times the input, twenty-five times the work (CodeQL js/polynomial-redos).
|
|
11
|
+
*
|
|
12
|
+
* A CLI is unlikely to be handed a 200k-character API base, so this is not an exploit so much as a
|
|
13
|
+
* pattern worth not shipping in a published package. The loop is linear, obvious, and faster on
|
|
14
|
+
* every input.
|
|
15
|
+
*/
|
|
16
|
+
export const normalizeApi = (raw) => {
|
|
17
|
+
const s = raw || '';
|
|
18
|
+
let end = s.length;
|
|
19
|
+
while (end > 0 && s[end - 1] === '/') end -= 1;
|
|
20
|
+
return s.slice(0, end);
|
|
21
|
+
};
|
|
6
22
|
|
|
7
23
|
/** Map a platform + URL to the browser-open command used to approve the device login. */
|
|
8
24
|
export const browserCommand = (platform, url) => {
|