From 45ce697eea6030d0c807b87c72005592c5930808 Mon Sep 17 00:00:00 2001 From: Rafael Calleja Date: Tue, 14 Apr 2026 07:50:53 +0200 Subject: [PATCH] fix: correct quote-handling alignment in extractBashCommands Replace quoted strings with same-length spaces in stripQuotedStrings so separator indices in the stripped string map correctly to the original. Add test coverage for quoted separators and isBashTool. --- src/bash-utils.ts | 2 +- tests/bash-commands.test.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/bash-utils.ts b/src/bash-utils.ts index fb83d148..c8bc9094 100644 --- a/src/bash-utils.ts +++ b/src/bash-utils.ts @@ -8,7 +8,7 @@ const BASH_TOOLS = new Set(['Bash', 'BashTool', 'PowerShellTool']) * command boundaries. */ function stripQuotedStrings(command: string): string { - return command.replace(/"[^"]*"|'[^']*'/g, '""') + return command.replace(/"[^"]*"|'[^']*'/g, match => ' '.repeat(match.length)) } export function extractBashCommands(command: string): string[] { diff --git a/tests/bash-commands.test.ts b/tests/bash-commands.test.ts index 4068d401..5895909c 100644 --- a/tests/bash-commands.test.ts +++ b/tests/bash-commands.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest' -import { extractBashCommands } from '../src/bash-utils.js' +import { extractBashCommands, isBashTool } from '../src/bash-utils.js' describe('extractBashCommands', () => { it('extracts single command', () => { @@ -49,4 +49,18 @@ describe('extractBashCommands', () => { it('handles command with quotes containing separators', () => { expect(extractBashCommands('echo "hello && world"')).toEqual(['echo']) }) + + it('handles quoted separators followed by real separator', () => { + expect(extractBashCommands('echo "hello && world" && git status')).toEqual(['echo', 'git']) + }) + + it('handles single-quoted separators', () => { + expect(extractBashCommands("echo 'hello && world'")).toEqual(['echo']) + }) +}) + +describe('isBashTool', () => { + it('recognizes Bash', () => { expect(isBashTool('Bash')).toBe(true) }) + it('recognizes BashTool', () => { expect(isBashTool('BashTool')).toBe(true) }) + it('rejects unknown tools', () => { expect(isBashTool('Read')).toBe(false) }) })