Skip to content

This should fix the issue in Parser.scan()#66

Merged
gdamore merged 3 commits intogdamore:mainfrom
dejlek:dejan/utf8-decoding-parser-scan-fix
Jan 14, 2026
Merged

This should fix the issue in Parser.scan()#66
gdamore merged 3 commits intogdamore:mainfrom
dejlek:dejan/utf8-decoding-parser-scan-fix

Conversation

@dejlek
Copy link
Copy Markdown
Contributor

@dejlek dejlek commented Jan 14, 2026

UTF-8 decoding in Parser.scan() is problematic. It uses decode(cast(string) accum, index) which involves an unsafe cast (violating immutability) and may fail to compile or run correctly if std.utf.decode expects a ref string. Furthermore, UTFException thrown by decode is not caught, which could crash the parser on invalid UTF-8 input.

I've also added tiny unittest for it.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of malformed UTF-8 so invalid sequences no longer crash or generate spurious events.
    • Added tests to verify invalid UTF-8 produces no events and valid multi-byte sequences are emitted in the correct order.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 14, 2026

📝 Walkthrough

Walkthrough

The parser's UTF-8 decoding now catches UTFException and only posts a Key.graph event on successful decode. Unit tests were added/updated to assert that invalid UTF-8 sequences produce no events and that valid multi-byte sequences followed by extra input yield the expected events.

Changes

Cohort / File(s) Summary
UTF-8 handling & tests
source/dcell/parser.d
Wrap UTF-8 decode in try/catch for UTFException; post Key.graph only on successful decode. Add/update unit tests to assert invalid UTF-8 produces no events and that a valid multi-byte sequence followed by further input emits the decoded char then subsequent events.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibble bytes both large and small,
I catch the crumbs before they fall,
A gentle hop, no crash in sight,
Valid char first, then on with flight,
Hooray—our parser sleeps tonight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'This should fix the issue in Parser.scan()' is vague and refers to fixing an unspecified issue without conveying the actual change—fixing UTF-8 decoding error handling. Use a more specific title that describes the actual fix, such as 'Fix UTF-8 decoding error handling in Parser.scan()' or 'Add try/catch for UTF-8 decoding in Parser'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa4543e and ee7c51c.

📒 Files selected for processing (1)
  • source/dcell/parser.d
🚧 Files skipped from review as they are similar to previous changes (1)
  • source/dcell/parser.d
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (macos-latest, ldc-latest)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Owner

@gdamore gdamore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this fix.

@gdamore gdamore merged commit c8aeec2 into gdamore:main Jan 14, 2026
5 checks passed
@gdamore
Copy link
Copy Markdown
Owner

gdamore commented Jan 14, 2026

AARGH. I forgot again to squash the sausage factory.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (4d1ac3e) to head (ee7c51c).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@    Coverage Diff     @@
##   main   #66   +/-   ##
==========================
==========================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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