Conversation
- Clamp substring range bounds in DocumentationComment._stripDocImports to avoid RangeError on offset drift. - Log element location and exception details when precaching local docs fails. - Add regression test for doc imports with non-ASCII characters and CRLF line endings. - Update CHANGELOG.md. Fixes dart-lang#4180
- Accumulate 30 lines of comments with non-ASCII em-dashes and CRLF. - Assert that comment text is preserved and @DocImport is removed without RangeError. Related to dart-lang#4180
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request fixes an unhandled RangeError that occurs during comment precaching when stripping @docImport directives containing non-ASCII characters or CRLF line endings. It resolves this by clamping the substring offsets to safe bounds within the content length. Additionally, it wraps the local documentation precaching in a try-catch block to log warnings with element location and exception details upon failure, and adds a test case to verify the fix. There are no review comments, so I have no feedback to provide.
Fixes #4180
Description
This PR fixes an unhandled
RangeErrorduring comment precaching when stripping@docImportdirectives in documentation comments containing non-ASCII characters (e.g. em-dash—or emojis) and CRLF line endings.safeStartandsafeEnd) to[0, content.length]inDocumentationComment._stripDocImportsso that string offset drift never causes a fatalRangeError.try-catchblock aroundprocessComment()inDocumentationComment.precacheLocalDocsthat logs the affected element location (location) and full identifier (fullyQualifiedName) withlogWarningbefore rethrowing, avoiding opaqueParallelWaitErrorfailures during batch doc precaching.test_docImport_withNonAsciiAndCrlfintest/documentation_comment_test.dart(stress testing with 30 accumulated lines of comments containing em-dashes and CRLF line endings) to verify that doc imports are stripped cleanly without error.## 9.0.10-wipinCHANGELOG.md.Verification
dart format.dart analyze(0 issues).test/documentation_comment_test.dart(50/50 passed).Contribution guidelines:
dart format.Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.