Split strings by code points when the separator is empty

Merged
MA
9d ago
+73-2

Closes #7842

StringVar.split() with no separator, or an empty one, compiled to JS str.split(""), which splits UTF-16 code units, so emoji and other characters outside the Basic Multilingual Plane broke into surrogate halves, unlike the other string operations that already work on code points since 0.11.

  • A literal empty separator now compiles to pyStrChars(...), the helper the other code-point operations use.
  • A separator that is only known at runtime compiles to pyStrSplit(s, sep), a new utils/state helper (sep === "" ? pyStrChars(s) : s.split(sep)), so the separator expression is evaluated once and no inline closure is emitted per call.
  • Non-empty literal separators still use str.split and add no import.

Tests: unit tests on the generated JS for split(), split(""), split(" ") and a state-var separator, and on the attached imports (they fail on main); pyStrSplit is covered in packages/reflex-frontend/tests/state.test.js and listed in public_api.test.js. The Unicode Playwright test now covers split().length(), foreach over split() and a runtime empty separator; I couldn't run Playwright locally, so that part relies on CI. pytest tests/units/test_var.py tests/units/vars tests/units/components/core: 561 passed; ruff check/format clean. A reflex-base bugfix news fragment is included.

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)