Skip to content

Conversation

@markijbema
Copy link

@markijbema markijbema commented Oct 23, 2025

Fixes this problem
CleanShot 2025-10-21 at 09 17 44

CleanShot 2025-10-21 at 09 17 59

After:
CleanShot 2025-10-23 at 10 32 26@2x

upstreamed from kilo ( Kilo-Org/kilocode#3104 );


Important

Adds support for multi-line git commit messages by handling newlines within quotes in command parsing and validation.

  • Behavior:
    • Adds protectNewlinesInQuotes() in command-validation-quote-protection.ts to replace newlines in quotes with placeholders.
    • Updates parseCommand() in command-validation.ts to use protectNewlinesInQuotes() for handling multi-line commands.
    • Ensures multi-line git commit messages are treated as single commands in getCommandDecision().
  • Tests:
    • Adds command-validation-quote-protection.spec.ts to test newline protection in quotes.
    • Updates command-validation.spec.ts to test multi-line command handling and validation logic.
  • Misc:
    • Introduces placeholders NEWLINE_PLACEHOLDER and CARRIAGE_RETURN_PLACEHOLDER for newline handling.

This description was created by Ellipsis for 7bdd67b. You can customize this summary. It will automatically update as commits are pushed.

…approve

- Add test case demonstrating current behavior where multi-line commit messages
  fail auto-approval due to newline splitting before quote handling
- Simplified reproduction of real-world scenario with git add && git commit -m
- Documents expected behavior for future fix
…sing

- Fix parseCommand() to protect newlines inside quoted strings before splitting
- Track quote state (single/double) and handle escaped quotes
- Use placeholder to preserve newlines in quotes during line splitting
- Restore actual newlines after parsing completes
- Update tests to expect newlines preserved in quoted strings
- Fixes auto-approve for multi-line git commit messages

This resolves the issue where multi-line git commit messages like:
  git commit -m "feat: title
  - point a
  - point b"
Were incorrectly split into separate commands, causing auto-approve to fail.
- Extract protectNewlinesInQuotes() as a separate, testable function
- Fix quote concatenation handling (e.g., echo '"'A'"' where A is NOT quoted)
- Properly track quote boundaries without using toggle-based state
- Handle escaped quotes correctly in double-quoted strings
- Add comprehensive test suite for protectNewlinesInQuotes():
  - Basic quote handling (single/double quotes)
  - Quote concatenation edge cases
  - Escaped quotes in different contexts
  - Unclosed quotes, empty strings, multiple newlines
  - Real-world git commit message examples
- All 153 tests pass
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 23, 2025
@markijbema markijbema marked this pull request as ready for review October 23, 2025 15:04
@markijbema markijbema requested review from cte, jr and mrubens as code owners October 23, 2025 15:04
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Oct 23, 2025
@roomote
Copy link

roomote bot commented Oct 23, 2025

Review Summary

I've reviewed the changes for adding support for multi-line git commit messages in auto-approve. The implementation is well-designed with comprehensive test coverage.

Issues Found

  • Escaped backslash handling in quote detection may not correctly handle consecutive backslashes before quotes (e.g., "test\\")

Positive Aspects

  • Clean separation of concerns with new command-validation-quote-protection.ts file
  • Comprehensive test coverage including edge cases
  • Proper handling of both \n and \r line endings
  • Correct implementation of quote concatenation rules

Follow Along on Roo Code Cloud

const quoteChar = command[i]
const prevChar = i > 0 ? command[i - 1] : ""

if (quoteChar === '"' && prevChar !== "\\") {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The escape check (prev char !== '\') only looks at the immediate previous character. For robust handling of multiple consecutive backslashes, consider counting the number of preceding backslashes.

Suggested change
if (quoteChar === '"' && prevChar !== "\\") {
if (quoteChar === '"' && (i === 0 || command.slice(0, i).match(/\\*$/)[0].length % 2 === 0)) {

@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Oct 23, 2025
Comment on lines +47 to +51
if (quoteChar === '"' && prevChar !== "\\") {
// Found closing quote
result += quoteChar
i++
break
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The escaped quote detection doesn't handle consecutive backslashes correctly. When you have an escaped backslash followed by a quote (e.g., "test\\" representing the shell command "test\"), the function checks only if the previous character is a backslash but doesn't verify if that backslash itself is escaped. This means "test\\" would be treated as having an escaped quote when the quote should actually close the string. While this edge case may be rare in git commit messages, it could cause newlines outside quotes to be incorrectly protected if a command contains escaped backslashes before quotes. Consider counting consecutive backslashes to properly determine if a quote is escaped.

Copy link

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review complete. Found 1 issue that should be addressed before approval. The escaped backslash handling edge case is a low-severity issue but should be fixed to ensure correctness in all scenarios.

@hannesrudolph hannesrudolph removed the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 23, 2025
@markijbema
Copy link
Author

Sure, I could improve the backslash detection

I disagree with roobot that 'correctness in all scenarios' is achievable though, because we are running this for all possible shells, and they might handle some string escaping different. In the end parsing shell commands ourselves will always have an inherent risk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: PR [Needs Prelim Review]

Development

Successfully merging this pull request may close these issues.

2 participants