mirror of
https://github.com/affaan-m/ECC.git
synced 2026-08-31 20:29:38 +02:00
fix(gateguard): match heredoc tab-strip order
This commit is contained in:
@@ -134,11 +134,12 @@ function hasLineContinuation(line) {
|
||||
function normalizeUnquotedHeredocLines(lines, stripTabs = false) {
|
||||
const logical = lines
|
||||
.map((line, index) => {
|
||||
if (index === lines.length - 1) return line;
|
||||
return hasLineContinuation(line) ? line.slice(0, -1) : `${line}\n`;
|
||||
const normalized = stripTabs ? line.replace(/^\t+/, '') : line;
|
||||
if (index === lines.length - 1) return normalized;
|
||||
return hasLineContinuation(normalized) ? normalized.slice(0, -1) : `${normalized}\n`;
|
||||
})
|
||||
.join('');
|
||||
return stripTabs ? logical.replace(/^\t+/, '') : logical;
|
||||
return logical;
|
||||
}
|
||||
|
||||
/** @returns {{ text: string, nextIndex: number }} */
|
||||
|
||||
@@ -1783,10 +1783,10 @@ function runTests() {
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('denies split options after tab-stripped heredoc line continuation', () => {
|
||||
expectDestructiveDeny(
|
||||
test('allows a joined command when tab stripping removes the option separator', () => {
|
||||
expectAllow(
|
||||
['cat <<-EOF', '\t$(rm\\', '\t-rf /tmp/expanded-target)', 'EOF'].join('\n'),
|
||||
'split option in tab-stripped unquoted heredoc substitution'
|
||||
'tab stripping joins rm and -rf into a harmless command name'
|
||||
);
|
||||
})
|
||||
)
|
||||
@@ -1794,10 +1794,10 @@ function runTests() {
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('preserves internal tabs after tab-stripped heredoc continuations', () => {
|
||||
expectAllow(
|
||||
test('denies split command names after tab-stripped heredoc continuations', () => {
|
||||
expectDestructiveDeny(
|
||||
['cat <<-EOF', '\t$(r\\', '\tm -rf /tmp/expanded-target)', 'EOF'].join('\n'),
|
||||
'internal tab after tab-stripped heredoc continuation'
|
||||
'split command name in tab-stripped unquoted heredoc substitution'
|
||||
);
|
||||
})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user