Skip to content

fix(schema): stepName truncates at byte boundary for multi-byte UTF-8 steps#104

Merged
greynewell merged 1 commit intomainfrom
fix-stepname-rune-truncation
Apr 9, 2026
Merged

fix(schema): stepName truncates at byte boundary for multi-byte UTF-8 steps#104
greynewell merged 1 commit intomainfrom
fix-stepname-rune-truncation

Conversation

@greynewell
Copy link
Copy Markdown
Contributor

Summary

stepName() extracted the HowToStep.name field for JSON-LD recipe structured data using byte operations:

  • len(step) > 80 — checked byte count, not rune count
  • step[:77] — byte slice that can land inside a multi-byte character
  • idx < 80 — compared a byte offset to a character limit

For instruction steps with multi-byte UTF-8 characters (é, ñ, CJK, emoji), step[:77] could split a character's byte sequence, producing invalid UTF-8 that json.Marshal silently replaces with \uFFFD.

Fix: compute runes := []rune(step), use len([]rune(step[:idx+1])) for the sentence guard, and string(runes[:77]) for truncation.

Test plan

  • TestStepName covers ASCII truncation (77+...=80 runes), sentence extraction, multi-byte step truncation (valid UTF-8, correct rune count), and multi-byte sentence guard
  • Existing TestParseDurationMinutes and TestComputeTotalTime still pass
  • go build ./... passes

🤖 Generated with Claude Code

… steps

stepName() used len(step)/step[:77] (byte operations) to enforce the 80-char
limit on HowToStep names in JSON-LD. For instruction steps containing multi-byte
UTF-8 characters (é, ñ, CJK, emoji), step[:77] could land inside a character's
byte sequence, producing invalid UTF-8 that json.Marshal silently replaces with
\uFFFD (U+FFFD).

The sentence-length guard (idx < 80) also compared a byte offset to 80,
incorrectly rejecting short multi-byte sentences that were < 80 runes but
> 80 bytes.

Fixes:
- Compute rune slice once: runes := []rune(step)
- Sentence guard: compare len([]rune(step[:idx+1])) < 80 (rune count)
- Truncation: string(runes[:77]) + "..." (rune slice, valid UTF-8)

Adds TestStepName covering ASCII truncation, sentence extraction, multi-byte
truncation (valid UTF-8 + correct rune count), and multi-byte sentence guard.

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 7 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 7 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: 33be0043-5434-4b71-b520-0be139409902

📥 Commits

Reviewing files that changed from the base of the PR and between 09bef24 and eb28d2c.

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

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

@greynewell greynewell merged commit 8947caa into main Apr 9, 2026
7 checks passed
@greynewell greynewell deleted the fix-stepname-rune-truncation branch April 9, 2026 18:46
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