Skip to content

fix(cobra): escape newlines, tabs, and carriage returns in kdlQuoteAlways#1

Merged
thecodesmith merged 2 commits intomainfrom
copilot/implement-escaping-special-characters
Mar 12, 2026
Merged

fix(cobra): escape newlines, tabs, and carriage returns in kdlQuoteAlways#1
thecodesmith merged 2 commits intomainfrom
copilot/implement-escaping-special-characters

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 12, 2026

kdlQuoteAlways only escaped \ and ", producing invalid KDL when CLI help text contained newlines, tabs, or carriage returns.

Changes

  • integrations/cobra/kdl.go: Add \n, \t, \r escaping to kdlQuoteAlways, after the backslash escape to prevent double-escaping

  • integrations/cobra/cobra_usage_test.go: Add TestSpecialCharacterEscaping (unit tests on kdlQuoteAlways directly), TestNewlineInCommandHelp, and TestSpecialCharsInFlagHelp

Example

// Input: cobra command with multiline Long description
cmd := &cobra.Command{
    Long: "First line.\nSecond line.\n\nThird paragraph.",
}

// Before: produced invalid KDL with literal newlines
long_about "First line.
Second line.

Third paragraph."

// After: correctly escaped
long_about "First line.\nSecond line.\n\nThird paragraph."

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Implement escaping for newlines and special characters fix(cobra): escape newlines, tabs, and carriage returns in kdlQuoteAlways Mar 12, 2026
Copilot AI requested a review from thecodesmith March 12, 2026 21:26
@thecodesmith thecodesmith marked this pull request as ready for review March 12, 2026 21:44
@thecodesmith thecodesmith merged commit 91be5a5 into main Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants