-
-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String functions UTF-8 issue #4109
Labels
Comments
toots
added a commit
that referenced
this issue
Aug 25, 2024
`"utf8"` * Add `string.chars` with encoding. * Fix default string escaping to properly fallback to `"ascii"` when utf8 escaping failed. Fixes: #4109
Thanks, that was a great suggestion! #4111 should take care of it. |
toots
added a commit
that referenced
this issue
Aug 25, 2024
`"utf8"` * Add `string.chars` with encoding. * Fix default string escaping to properly fallback to `"ascii"` when utf8 escaping failed. Fixes: #4109
toots
added a commit
that referenced
this issue
Aug 25, 2024
`"utf8"` * Add `string.chars` with encoding. * Fix default string escaping to properly fallback to `"ascii"` when utf8 escaping failed. Fixes: #4109
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).
The text was updated successfully, but these errors were encountered: