aboutsummaryrefslogtreecommitdiff
path: root/src/coreutils.js
diff options
context:
space:
mode:
authorSoccera1 <[email protected]>2026-07-18 07:51:42 +1000
committerSoccera1 <[email protected]>2026-07-18 07:51:42 +1000
commita753f669c9bedfccb9f7f400da018bb487dca5d0 (patch)
tree6a5600e6719a6dd69ef035f8f22fea37bd4ea8c1 /src/coreutils.js
parent8b8e40523f999fa2e2d676f591ac85c60f063083 (diff)
downloadbnu-a753f669c9bedfccb9f7f400da018bb487dca5d0.tar.gz
bnu-a753f669c9bedfccb9f7f400da018bb487dca5d0.zip
Fix shell quoting
Diffstat (limited to 'src/coreutils.js')
-rw-r--r--src/coreutils.js19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/coreutils.js b/src/coreutils.js
index e4353bf..aabcac1 100644
--- a/src/coreutils.js
+++ b/src/coreutils.js
@@ -14836,7 +14836,7 @@ function lsResolvedQuotingStyle(opts) {
if (opts.N) return "literal";
if (opts.Q || opts["quote-name"]) return "c";
const style = opts.quoting ?? opts["quoting-style"];
- return resolveLsQuotingStyle(style) ?? (opts.q ? "question" : "literal");
+ return resolveLsQuotingStyle(style) ?? (opts.q ? "question" : process.stdout.isTTY ? "shell-escape" : "literal");
}
function lsQuestionName(name) {
@@ -14883,22 +14883,31 @@ function shellEscapeLsName(name, always = false) {
if (!/[\x00-\x1f\x7f]/.test(text)) return shellQuoteLsName(text, always);
const parts = [];
let plain = "";
- const flush = () => {
+ let escaped = "";
+ const flushPlain = () => {
if (plain) {
parts.push(`'${plain.replaceAll("'", "'\\''")}'`);
plain = "";
}
};
+ const flushEscaped = () => {
+ if (escaped) {
+ parts.push(`$'${escaped}'`);
+ escaped = "";
+ }
+ };
for (const ch of text) {
const code = ch.codePointAt(0);
if (code < 32 || code === 127) {
- flush();
- parts.push(`$'${lsEscapedName(ch)}'`);
+ flushPlain();
+ escaped += lsEscapedName(ch);
} else {
+ flushEscaped();
plain += ch;
}
}
- flush();
+ flushPlain();
+ flushEscaped();
if (!parts.length) return "''";
if (always && parts.length === 1 && !parts[0].startsWith("$")) return parts[0];
return parts.join("");