mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-03-30 13:43:26 +08:00
fix(hooks): allow tmux-wrapped dev server commands (#321)
* fix(hooks): fix shell splitter redirection/escape bugs, extract shared module - Fix single & incorrectly splitting redirection operators (&>, >&, 2>&1) - Fix escaped quotes (\", \') not being handled inside quoted strings - Extract splitShellSegments into shared scripts/lib/shell-split.js to eliminate duplication between hooks.json, before-shell-execution.js, and pre-bash-dev-server-block.js - Add comprehensive tests for shell splitting edge cases * fix(hooks): handle backslash escapes outside quotes in shell splitter Escaped operators like \&& and \; outside quotes were still being treated as separators. Add escape handling for unquoted context.
This commit is contained in:
@@ -2,40 +2,7 @@
|
||||
'use strict';
|
||||
|
||||
const MAX_STDIN = 1024 * 1024;
|
||||
|
||||
function splitShellSegments(command) {
|
||||
const segments = [];
|
||||
let current = '';
|
||||
let quote = null;
|
||||
|
||||
for (let i = 0; i < command.length; i++) {
|
||||
const ch = command[i];
|
||||
if (quote) {
|
||||
if (ch === quote) quote = null;
|
||||
current += ch;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch === '"' || ch === "'") {
|
||||
quote = ch;
|
||||
current += ch;
|
||||
continue;
|
||||
}
|
||||
|
||||
const next = command[i + 1] || '';
|
||||
if (ch === ';' || (ch === '&' && next === '&') || (ch === '|' && next === '|') || (ch === '&' && next !== '&')) {
|
||||
if (current.trim()) segments.push(current.trim());
|
||||
current = '';
|
||||
if ((ch === '&' && next === '&') || (ch === '|' && next === '|')) i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
current += ch;
|
||||
}
|
||||
|
||||
if (current.trim()) segments.push(current.trim());
|
||||
return segments;
|
||||
}
|
||||
const { splitShellSegments } = require('../lib/shell-split');
|
||||
|
||||
let raw = '';
|
||||
process.stdin.setEncoding('utf8');
|
||||
|
||||
Reference in New Issue
Block a user