Skip to content

Conversation

Omkarthipparthi
Copy link

Description

Fixes crash when using RTL text plugin with formatted text-field expressions where all sections evaluate to empty strings.

Closes #6444

Problem

When using the RTL text plugin (@mapbox/[email protected]) with a formatted text-field where all sections are empty (e.g., both name and ref are null), the application crashes with:

Root Cause

The RTL plugin's processStyledBidirectionalText can return either:

  • Tuples: [text, sectionIndex] (expected format)
  • Objects: {text, sectionIndex} (some plugin versions/edge cases)

The shaping code in src/symbol/shaping.ts only handled tuples, causing taggedLine.text to be undefined when objects were returned, leading to crashes when later code accessed this.text.length.

Solution

Added defensive normalization logic (lines 331-361 in shaping.ts) to:

  • Accept both tuple [text, sectionIndex] and object {text, sectionIndex} formats
  • Provide safe fallbacks: empty string '' for text, empty array [] for sectionIndex
  • Maintain backward compatibility with all RTL plugin versions

Testing

  • All 17 integration shaping tests pass
  • All 2476 unit tests pass (including 10 shaping-specific tests)
  • Tested locally with @mapbox/[email protected]
  • No regressions in existing functionality

Test Cases Verified

  1. Empty formatted sections (the bug repro) - No crash
  2. Arabic text with multiple sections - Renders correctly
  3. Hebrew + English mixed RTL/LTR - Renders correctly
  4. Partial empty sections (only name or ref) - Handles gracefully

Checklist

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.

Undefined text property for formatted text with multiple empty sections and right to left plugin

1 participant