Skip to content

fix(build): truncate search index descriptions by rune count not bytes#100

Merged
greynewell merged 2 commits intomainfrom
fix-search-index-rune-truncation
Apr 9, 2026
Merged

fix(build): truncate search index descriptions by rune count not bytes#100
greynewell merged 2 commits intomainfrom
fix-search-index-rune-truncation

Conversation

@greynewell
Copy link
Copy Markdown
Contributor

Summary

  • generateSearchIndex was using len(desc) > 120 / desc[:120] — byte operations — to cap description length before writing the search index JSON
  • For multi-byte UTF-8 characters (é, ñ, ü, CJK, emoji), slicing at byte position 120 can land inside a character's byte sequence, producing an invalid byte string
  • json.Marshal silently replaces invalid UTF-8 with U+FFFD (replacement character \uFFFD) — so the search index would contain corrupted descriptions with no error returned
  • Fix: convert to []rune, check/slice by rune count, convert back to string

Regression test added in build_test.go:

  • Short description written verbatim
  • Long ASCII description truncated to exactly 120 runes
  • 121-rune string of é (2 bytes each) truncated at rune boundary → valid UTF-8
  • Search disabled → no file written

Test plan

  • go test ./internal/archdocs/pssg/build/... passes
  • go build ./... passes
  • TestGenerateSearchIndex_MultiByteDescriptionTruncation fails on the old byte-slice code and passes on the fix

🤖 Generated with Claude Code

greynewell and others added 2 commits April 9, 2026 14:29
…cation

Adds build_test.go covering generateSearchIndex:
- short description written verbatim
- long ASCII description truncated to exactly 120 runes
- multi-byte (é, 2-byte) description truncated at rune boundary → valid UTF-8
- search disabled → no file written

Regression for the byte-slice truncation bug fixed in build.go.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
generateSearchIndex was using len(desc)/desc[:120] (byte operations) to
limit descriptions to 120 characters. For multi-byte UTF-8 characters
(é, ñ, ü, CJK, emoji) this could split a character in the middle,
producing a replacement character (U+FFFD) when json.Marshal silently
replaces invalid UTF-8 sequences in the output JSON.

Fix: convert to []rune, check/slice by rune count, convert back to string.

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 4 minutes and 42 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 4 minutes and 42 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: 0cfe7e65-46b8-4d3d-a70d-9e1736b3fcd2

📥 Commits

Reviewing files that changed from the base of the PR and between ac01b6d and 79338bb.

📒 Files selected for processing (2)
  • internal/archdocs/pssg/build/build.go
  • internal/archdocs/pssg/build/build_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-search-index-rune-truncation

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

@greynewell greynewell merged commit 88cb8c7 into main Apr 9, 2026
7 checks passed
@greynewell greynewell deleted the fix-search-index-rune-truncation branch April 9, 2026 18:39
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