-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix: handle multiline quoted strings in command auto-approval #10228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ote-aware parsing
Re-reviewed this PR. The escaped backslash handling issue has been fixed correctly. All 36 tests pass.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
src/shared/parse-command.ts
Outdated
| const prevChar = i > 0 ? command[i - 1] : "" | ||
|
|
||
| // Handle escape sequences (only in double quotes, single quotes are literal) | ||
| const isEscaped = prevChar === "\\" && inDoubleQuote |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor edge case: The escape detection only checks if prevChar === "\\", but doesn't track whether the backslash itself was escaped. For input containing \\" (escaped backslash followed by quote), the quote should end the string, but this code would treat it as escaped. For example, echo "hello\\"\nworld would be incorrectly treated as a single multiline string instead of two separate lines. This is unlikely to affect typical beads commands but could cause unexpected behavior in edge cases. A fix would require tracking consecutive backslash count (odd = real escape, even = escaped backslash).
Fix it with Roo Code or mention @roomote and request a fix.
|
@roomote Can't we take a step back? I think execution is different than checking which commands to run. So as long as we join all the commands by newlines, then split on &&, |, maybe other signs, we can find out which commands they are? Just make sure that the original string is executed. Or maybe that happens already. What I forsee then is that strings containing bash separator symbols are split (&&, |), but maybe we can find a solution. what do you think? Maybe just a newline regex should be fine, then we can fix the other bugs later. I assume most commands are single line anyway except for strings, so I'm not sure what reason was to have splitting on new lines? |
Fixed the escaped backslash handling issue. All local checks passed. |
Fixed the escape detection logic in joinQuotedLines() to properly count consecutive backslashes. A quote is only escaped if preceded by an odd number of backslashes: - \\" = escaped backslash + closing quote (string ends) - \\\" = escaped backslash + escaped quote (string continues) Added test cases to verify the fix.
|
Good question about the approach. After analyzing the code, here's why newline splitting is necessary: Why we can't just split on operators (&&, ||, ;, |): In bash/shell scripts, newlines ARE command separators. Multi-line inputs like: echo allowed
rm deniedshould be validated as TWO separate commands for auto-approval. The What the current PR does: The
This is essentially "a newline regex" but with quote-awareness added. The execution still uses the original string unchanged. Current state:
No code changes were needed - the current implementation addresses your concern about execution using the original string while also correctly parsing commands for validation. |
|
Ok let's go for review @roomote |
Reviewed the PR and confirmed all identified issues have been addressed:
The reviewer has confirmed all 36 tests pass. No additional fixes are needed - the PR is ready for merge. |
|
@roomote can we exit draft status? |
Done! PR #10228 is now marked as ready for review. |
Reviewed this PR. All identified issues have been addressed. All 36 tests pass.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Related GitHub Issue
Closes: #10226
Description
This PR attempts to address Issue #10226 where multiline commands with quoted strings (like beads descriptions) were not being auto-approved even when the command prefix was in the allowed list.
Root Cause: The
parseCommandfunction insrc/shared/parse-command.tssplit by newlines before checking quote boundaries. This caused multiline quoted strings to be incorrectly split into invalid fragments.Solution: Added a new
joinQuotedLines()function that properly tracks quote state while iterating through the input, preserving newlines within quoted strings as part of the command rather than treating them as line separators.This approach:
This addresses feedback from @tanevanwifferen on the original implementation approach.
Test Procedure
src/shared/__tests__/parse-command.spec.tsRun tests:
cd src && npx vitest run shared/__tests__/parse-command.spec.tsPre-Submission Checklist
Documentation Updates
Additional Notes
Feedback and guidance are welcome!
Important
Fixes multiline quoted strings handling in
parseCommandby introducingjoinQuotedLines()and adds comprehensive tests.parseCommandinparse-command.tsby introducingjoinQuotedLines().joinQuotedLines()preserves newlines within quotes, handles single/double quotes, escaped quotes, and different line endings.parse-command.spec.tsfor multiline quoted strings, line endings, and command chaining.parseCommandto usejoinQuotedLines()for initial line processing.This description was created by
for 62d74cb. You can customize this summary. It will automatically update as commits are pushed.