Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
The string functions only seem to work well with ASCII characters but not with Unicode characters (UTF-8).
Unicode characters are counted twice or three times, which leads to incorrect calculations.
Steps to reproduce
The issue is reproducible with the official package 2.2.5 (and earlier) and with the Rolling Release 2.3.x (tested with build 4980bc0).
Here are some examples using Liquidsoap's interactive interpreter:
ASCII (working correctly)string.length("e");; - : int = 1
string.length("o");; - : int = 1
string.length("~");; - : int = 1
UTF-8
string.length("é");; - : int = 2string.length("ö");; - : int = 2string.length("€");; - : int = 3
Here is a more practical example of extracting the name of a song as substring.
If the band name is in ASCII characters, the result is correct:
string.sub("Queensryche - Silent lucidity (live)", start=14, length=15);; - : string = "Silent lucidity"
In the original notation of the band name, which contains an UTF-8 special character, the result is shifted by one character:
string.sub("Queensrÿche - Silent lucidity (live)", start=14, length=15);; - : string = " Silent lucidit"
Expected behavior
Each UTF-8 character should only be counted as one character so that calculations with string functions generate correct results.
Liquidsoap version
Liquidsoap 2.3.0+git@4980bc075
Copyright (c) 2003-2024 Savonet team
Liquidsoap is open-source software, released under GNU General Public License.
See <http://liquidsoap.info> for more information.
Description
The string functions only seem to work well with ASCII characters but not with Unicode characters (UTF-8). Unicode characters are counted twice or three times, which leads to incorrect calculations.
Steps to reproduce
The issue is reproducible with the official package 2.2.5 (and earlier) and with the Rolling Release 2.3.x (tested with build 4980bc0).
Here are some examples using Liquidsoap's interactive interpreter:
ASCII (working correctly)
string.length("e");;
- : int = 1string.length("o");;
- : int = 1string.length("~");;
- : int = 1UTF-8
string.length("é");;
- : int = 2string.length("ö");;
- : int = 2string.length("€");;
- : int = 3Here is a more practical example of extracting the name of a song as substring. If the band name is in ASCII characters, the result is correct:
string.sub("Queensryche - Silent lucidity (live)", start=14, length=15);;
- : string = "Silent lucidity"In the original notation of the band name, which contains an UTF-8 special character, the result is shifted by one character:
string.sub("Queensrÿche - Silent lucidity (live)", start=14, length=15);;
- : string = " Silent lucidit"Expected behavior
Each UTF-8 character should only be counted as one character so that calculations with string functions generate correct results.
Liquidsoap version
Liquidsoap build config
Installation method
From official packages in the release artifacts
Additional Info
Tested with Debian 12 and Ubuntu 24.04 (AMD64).