@socketsecurity/lib 3.4.0 → 3.5.0
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/CHANGELOG.md +8 -0
- package/dist/argv/quote.d.ts +49 -0
- package/dist/argv/quote.js +42 -0
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.5.0](https://github.com/SocketDev/socket-lib/releases/tag/v3.5.0) - 2025-11-14
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **argv/quote**: New utilities for quoting command-line arguments when using `spawn()` with `shell: true`
|
|
13
|
+
- `posixQuote(arg)`: Quote arguments for POSIX shells (bash, sh, zsh) using single quotes
|
|
14
|
+
- `win32Quote(arg)`: Quote arguments for Windows cmd.exe using double quotes
|
|
15
|
+
|
|
8
16
|
## [3.4.0](https://github.com/SocketDev/socket-lib/releases/tag/v3.4.0) - 2025-11-14
|
|
9
17
|
|
|
10
18
|
### Added
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Argument quoting utilities for shell execution with spawn()
|
|
3
|
+
*
|
|
4
|
+
* These functions handle quoting of command-line arguments when using
|
|
5
|
+
* child_process.spawn() with shell: true.
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: Only needed when shell: true. With shell: false, arguments
|
|
8
|
+
* are passed directly to the OS kernel as an array (no quoting needed).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Quote an argument for POSIX shell execution (bash, sh, zsh).
|
|
12
|
+
*
|
|
13
|
+
* Uses single quotes (POSIX standard) which prevent all expansions except
|
|
14
|
+
* single quotes themselves. Internal single quotes are escaped using '\''
|
|
15
|
+
*
|
|
16
|
+
* @param arg - Argument to quote
|
|
17
|
+
* @returns Quoted argument safe for POSIX shells when using shell: true
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { posixQuote } from '@socketsecurity/lib/argv/quote'
|
|
22
|
+
*
|
|
23
|
+
* // With shell: true on Unix
|
|
24
|
+
* const path = '/path/with spaces/file.txt'
|
|
25
|
+
* spawn('sh', ['-c', 'cat', posixQuote(path)], { shell: true })
|
|
26
|
+
* // sh receives: sh -c cat '/path/with spaces/file.txt'
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function posixQuote(arg: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Quote an argument for Windows cmd.exe shell execution.
|
|
32
|
+
*
|
|
33
|
+
* Uses double quotes (cmd.exe standard) and escapes internal quotes by doubling.
|
|
34
|
+
* Handles all cmd.exe special characters: space, &, |, <, >, ^, %, (, ), !, "
|
|
35
|
+
*
|
|
36
|
+
* @param arg - Argument to quote
|
|
37
|
+
* @returns Quoted argument safe for cmd.exe when using shell: true
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { win32Quote } from '@socketsecurity/lib/argv/quote'
|
|
42
|
+
*
|
|
43
|
+
* // With shell: true on Windows
|
|
44
|
+
* const path = 'C:\\Program Files\\app.exe'
|
|
45
|
+
* spawn('cmd', ['/c', 'app', win32Quote(path)], { shell: true })
|
|
46
|
+
* // cmd.exe receives: cmd /c app "C:\Program Files\app.exe"
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function win32Quote(arg: string): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Socket Lib - Built with esbuild */
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var quote_exports = {};
|
|
21
|
+
__export(quote_exports, {
|
|
22
|
+
posixQuote: () => posixQuote,
|
|
23
|
+
win32Quote: () => win32Quote
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(quote_exports);
|
|
26
|
+
function posixQuote(arg) {
|
|
27
|
+
if (!/[\s&|<>$`\\*?[\](){};"'~!#]/.test(arg)) {
|
|
28
|
+
return arg;
|
|
29
|
+
}
|
|
30
|
+
return `'${arg.replace(/'/g, "'\\''")}'`;
|
|
31
|
+
}
|
|
32
|
+
function win32Quote(arg) {
|
|
33
|
+
if (!/[\s&|<>^%()!"]/.test(arg)) {
|
|
34
|
+
return arg;
|
|
35
|
+
}
|
|
36
|
+
return `"${arg.replace(/"/g, '""')}"`;
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
posixQuote,
|
|
41
|
+
win32Quote
|
|
42
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@socketsecurity/lib",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"packageManager": "pnpm@10.22.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Core utilities and infrastructure for Socket.dev security tools",
|
|
@@ -111,6 +111,10 @@
|
|
|
111
111
|
"types": "./dist/argv/parse.d.ts",
|
|
112
112
|
"default": "./dist/argv/parse.js"
|
|
113
113
|
},
|
|
114
|
+
"./argv/quote": {
|
|
115
|
+
"types": "./dist/argv/quote.d.ts",
|
|
116
|
+
"default": "./dist/argv/quote.js"
|
|
117
|
+
},
|
|
114
118
|
"./arrays": {
|
|
115
119
|
"types": "./dist/arrays.d.ts",
|
|
116
120
|
"default": "./dist/arrays.js"
|
|
@@ -687,7 +691,7 @@
|
|
|
687
691
|
"@socketregistry/is-unicode-supported": "1.0.5",
|
|
688
692
|
"@socketregistry/packageurl-js": "1.3.5",
|
|
689
693
|
"@socketregistry/yocto-spinner": "1.0.25",
|
|
690
|
-
"@socketsecurity/lib-stable": "npm:@socketsecurity/lib@3.
|
|
694
|
+
"@socketsecurity/lib-stable": "npm:@socketsecurity/lib@3.4.0",
|
|
691
695
|
"@types/node": "24.9.2",
|
|
692
696
|
"@typescript/native-preview": "7.0.0-dev.20250920.1",
|
|
693
697
|
"@vitest/coverage-v8": "4.0.3",
|