fix(cli): sanitize tabs in aligned table output (PR #22 review)#26
Open
so0k wants to merge 3 commits into
Open
fix(cli): sanitize tabs in aligned table output (PR #22 review)#26so0k wants to merge 3 commits into
so0k wants to merge 3 commits into
Conversation
writeAlignedColumns joined cells with \t and fed them to text/tabwriter, so a tab inside any cell (catalog description or skill name/reason, taken verbatim and not guaranteed tab-free) was read as an extra column separator and corrupted the alignment this slice added. Sanitize \t/\n/\r to spaces in each cell before joining, with a unit test proving a tabbed cell can no longer inject a column. Also break tabwriter.NewWriter onto one argument per line (style: 4+ args), per the Qodo review on PR #22. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The PostToolUse hook embedded a long multi-statement shell command on a single JSON line (>120 chars, unreviewable). Move the logic into .claude/hooks/ascii-guard.sh and reference it from .claude/settings.json, so the guard is readable, executable, and independently testable. Behavior is unchanged (clean .go -> 0, non-go -> 0, violation -> exit 2). Per the Qodo review on PR #22. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Review Summary by QodoSanitize control characters in aligned table output
WalkthroughsDescription• Sanitize tabs/newlines in table cells to prevent alignment corruption - Tabs were read as column separators by tabwriter, breaking layout - Newlines/carriage-returns broke row invariants - All control characters replaced with spaces before joining • Add unit test proving tabbed cells cannot inject columns • Improve code style by breaking tabwriter.NewWriter onto separate lines • Extract long hook command into dedicated shell script for maintainability Diagramflowchart LR
A["Cell content<br/>with tabs/newlines"] --> B["cellSanitizer<br/>replaces control chars"]
B --> C["Safe cells<br/>joined with tabs"]
C --> D["tabwriter<br/>renders aligned columns"]
E["Long hook command<br/>in JSON"] --> F["Extracted to<br/>ascii-guard.sh"]
F --> G["Referenced from<br/>settings.json"]
File Changes1. internal/cli/output.go
|
Code Review by Qodo
1.
|
…review)
When CLAUDE_PROJECT_DIR is unset/empty the hook command resolved to
/.claude/hooks/ascii-guard.sh, so bash could not find the script and the
guard was silently skipped. Default it to '.' (matching the script's own
cd "${CLAUDE_PROJECT_DIR:-.}") so the guard still runs. Per the Qodo review
on PR #26.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #22, addressing the Qodo review on that PR.
Summary
writeAlignedColumns). Cells were\t-joined and fed totext/tabwriter, so a tab inside any cell (catalog description or skill name/reason — taken verbatim, not guaranteed tab-free) was read as an extra column separator and broke alignment. Now each cell is sanitized (\t/\n/\r→ space) before joining, with a unit test proving a tabbed cell can't inject a column.tabwriter.NewWriterargs broken onto one-arg-per-line (rule 782553 / our owngolang-code-style).PostToolUsehook's long single-line shell command (>120 chars, rule 782552) now lives in.claude/hooks/ascii-guard.sh, referenced from.claude/settings.json. Behavior unchanged.Not included (deliberate)
truncateDescusing…instead of ASCII...(rule 783450). That conflicts with the maintainer's decision to keep the intentional output glyphs, and changing an org-wide rule vs. complying is a pending governance call — left out of this PR.Test plan
make checkgreen: gofmt,go vet, golangci-lint 0 issues, all tests (incl. integration).TestWriteAlignedColumns_NeutralizesTabsInCellspasses..go→ exit 0, non-Go → exit 0 (skipped), injectedU+201C→ exit 2 with location on stderr.🤖 Generated with Claude Code