Issue #202: Special case for empty substring that splits surrogate pair.

The code to split non-BMP characters into surrogate pairs assumes that
we are actually splitting a character, and will fail when we ask it to
create a zero-length string in the middle of a surrogate pair split.

Special case zero-length substrings to work around this.
This commit is contained in:
Tor Andersson
2025-06-16 15:48:52 +02:00
parent 4bfb1a2575
commit f5b6492769

View File

@@ -288,8 +288,10 @@ static void Sp_slice(js_State *J)
if (s < e)
Sp_substring_imp(J, str, s, e - s);
else
else if (s > e)
Sp_substring_imp(J, str, e, s - e);
else
js_pushliteral(J, "");
}
static void Sp_substring(js_State *J)
@@ -304,8 +306,10 @@ static void Sp_substring(js_State *J)
if (s < e)
Sp_substring_imp(J, str, s, e - s);
else
else if (s > e)
Sp_substring_imp(J, str, e, s - e);
else
js_pushliteral(J, "");
}
static void Sp_toLowerCase(js_State *J)