Fix HTML trailing newline accessibility crash#145
Conversation
Crashlytics: https://console.firebase.google.com/u/0/project/hackerspub-android/crashlytics/app/android:pub.hackers.android/issues/970e0c4edebb1afa31c7867b373dec64?time=7d&types=crash&sessionEventKey=69E6FD270331000138BB1A3827BF86CE_2209511287297688744 The reported crash comes from Compose accessibility while resolving character locations for text: AndroidComposeViewAccessibilityDelegateCompat.addExtraDataToAccessibilityNodeInfoHelper() calls TextLayoutResult.getBoundingBox(), which reaches MultiParagraph.getBoundingBox() and throws IllegalArgumentException: Found paragraph index -2 should be in range [0, 1). The debug info shows index=2420 with paragraphs=[[0, 2420)], so accessibility asked for the paragraph end boundary rather than a drawable character inside the paragraph. This appears to be a Compose text/accessibility bug: a trailing newline at the end of a Text/ClickableText layout can be treated as part of the accessibility text range, but it has no glyph bounding box in the laid-out paragraph. Compose should defensively ignore or null out that character-location request instead of crashing the app. Normalize parsed HTML by trimming only trailing rendered line breaks from the AnnotatedString. Interior newlines and paragraph spacing are preserved, while HTML parser artifacts such as Hello<br> or compact lists ending in a final newline no longer expose the vulnerable trailing boundary to Compose accessibility. Tests cover trailing <br> and compact list output.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
Summary
AnnotatedStringoutput.<br>and compact list output.Crash Context
Crashlytics issue: https://console.firebase.google.com/u/0/project/hackerspub-android/crashlytics/app/android:pub.hackers.android/issues/970e0c4edebb1afa31c7867b373dec64?time=7d&types=crash&sessionEventKey=69E6FD270331000138BB1A3827BF86CE_2209511287297688744
Relevant stack trace path:
The key detail is
index=2420withparagraphs=[[0, 2420)]: accessibility requested a character bounding box at the paragraph end boundary. That boundary can happen when our HTML parser leaves a trailing rendered newline in aClickableTextnode. A trailing newline is part of the text range but does not have a drawable glyph bounding box inside the laid-out paragraph.This looks like a Compose text/accessibility bug as well: Compose should defensively ignore the request or return
nullfor that character-location entry instead of crashing the app. Since the app can avoid feeding this vulnerable trailing boundary without changing user-visible content, this PR normalizes the parsed HTML output by trimming only trailing\ncharacters.Verification