Skip to content

$substring throws IndexOutOfBoundsException on strings with non-BMP characters when length is omitted or too large #461

Open

Description

@aeberhart

Problem

$substring(str, start) throws java.lang.IndexOutOfBoundsException when str contains a non-BMP character (a code point above U+FFFF, stored in Java as a surrogate pair). This includes emoji such as 😀 (U+1F600) and also mathematical letters such as 𝒳 (U+1D4B3).

JSONata JS counts code points and returns the substring.

Reproduce

$substring('😀bc', 1)
$substring('𝒳bc', 1)
$substring('😀bc', 0, 10)