Skip to content

fix(graph): rune-based truncation in dotEscape prevents invalid UTF-8 in DOT output#105

Merged
greynewell merged 3 commits intomainfrom
fix-dotescape-rune-truncation
Apr 9, 2026
Merged

fix(graph): rune-based truncation in dotEscape prevents invalid UTF-8 in DOT output#105
greynewell merged 3 commits intomainfrom
fix-dotescape-rune-truncation

Conversation

@greynewell
Copy link
Copy Markdown
Contributor

Summary

  • dotEscape in internal/graph/handler.go used byte-based indexing (s[len(s)-39:]) to trim long node names in DOT graph output
  • For node names with multi-byte UTF-8 characters (accented letters, CJK paths, etc.), the byte offset could land mid-character, producing invalid UTF-8
  • Invalid UTF-8 in a .dot file causes Graphviz and other DOT consumers to fail or emit garbage
  • Fix: convert to []rune, compare and slice by rune index

Regression test

TestWriteDOT_LongNameTruncated_MultiByteUTF8: 41 × "é" (2 bytes each = 82 bytes, 41 runes). The old s[82-39:] = s[43:] starts at the second byte of U+00E9 (encoded 0xC3 0xA9), producing invalid UTF-8. The fix slices by rune index and produces valid UTF-8 with the correct 39-rune tail.

Test plan

  • go test ./internal/graph/ — all tests pass including new regression test
  • go build ./... — clean

🤖 Generated with Claude Code

greynewell and others added 3 commits April 9, 2026 14:42
writeGraphData computed lineCount only when startLine > 0 && endLine > 0.
For nodes without a startLine (API returns 0), the condition was false and
lineCount remained 0, so the graph visualisation data showed lc=0 even
though the same node's frontmatter correctly computed line_count=endLine
(using effectiveStart=1).

Fix: mirror the effectiveStart=1 defaulting used by all frontmatter writers
— if endLine > 0 but startLine <= 0, treat startLine as 1.

Adds TestGraphDataLineCountMissingStartLine to catch the regression.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
goimports rejects manually aligned spaces; use single space.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
dotEscape used byte indexing (s[len(s)-39:]) to take the last 39
characters of a node name. For names with multi-byte UTF-8 characters
(e.g. accented letters, CJK paths), the byte offset could land in the
middle of a multi-byte sequence, producing invalid UTF-8 in the DOT
output and breaking downstream Graphviz tools.

Fix: convert to []rune and slice by rune index.

Adds TestWriteDOT_LongNameTruncated_MultiByteUTF8 as a regression test
(41 × "é" → the old byte slice cut byte 43, which is the second byte of
U+00E9, producing invalid UTF-8).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Warning

Rate limit exceeded

@greynewell has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 12 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 0 minutes and 12 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9a5b6445-d1f4-4a7b-a8e5-bcf49254aeee

📥 Commits

Reviewing files that changed from the base of the PR and between 8fa3e47 and f0cfd24.

📒 Files selected for processing (4)
  • internal/archdocs/graph2md/graph2md.go
  • internal/archdocs/graph2md/graph2md_test.go
  • internal/graph/handler.go
  • internal/graph/handler_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-dotescape-rune-truncation

Comment @coderabbitai help to get the list of available commands and usage tips.

@greynewell greynewell merged commit 161c66e into main Apr 9, 2026
7 checks passed
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.

1 participant