Page 1 of 1

UTF-8 decoding issue

Posted: Fri Jan 06, 2023 11:44 pm
by elfrea
Hi everyone, i've stumbled nto an UTF-8 decoding issue.

I've made a function to fetch all files from a specified path.
everything is working well, but when checking a certain folder content, my program would crash saying :
UTF-8 decoding error: Invalid UTF-8

i've checked with the file explorer to see what could cause such an issue, and i've found the problem.
It was simply a file with a 'é' character that caused the crash. Once i renamed the file and removed the 'é',
everything was ok.

I'm kinda puzzled how I could solve this issue, it seems to me that it is a LOVE UTF-8 decoding issue

btw, i simply used io.popen("dir ./path/ /b /a-d") and inserted every lines in a table. In case it should help to specify where that character comes from exactly. And when it crashe4d exactly is when i try to use 'love.graphics.print' with that string i got from the 'dir' command.

could someone help me out with that please?

Re: UTF-8 decoding issue

Posted: Sat Jan 07, 2023 2:07 am
by slime
love expects all text used with love.graphics.print and friends to have UTF-8 text encoding. On Windows, functions that are very thin wrappers around Windows APIs (such as io.popen) don't return UTF-8 text.

If you use something like love.filesystem.getDirectoryItems instead of that io.popen command then there won't be a problem, because getDirectoryItems makes sure to return UTF-8 encoded text for each filename.

You could also convert the text returned by popen from whatever encoding it is in (probably UTF-16) to UTF-8, but that might be a lot more work than other solutions.

Re: UTF-8 decoding issue

Posted: Sat Jan 07, 2023 5:41 am
by elfrea
yeah i understand. but i cant really use the love.filesystem functions because i read that you're locked inside the 'game folder' probably in "appdata" folder. I got to have access to the whole file system. I'll just let it go for now, and i'll probably do either a conversion like u said, or maybe the lazy solution, just catching the error and dropping that file completely since it doesnt really matter that much.
anyway, thanks for the reply!

Re: UTF-8 decoding issue

Posted: Sat Jan 07, 2023 9:12 pm
by zorg
elfrea wrote: Sat Jan 07, 2023 5:41 am yeah i understand. but i cant really use the love.filesystem functions because i read that you're locked inside the 'game folder' probably in "appdata" folder. I got to have access to the whole file system. I'll just let it go for now, and i'll probably do either a conversion like u said, or maybe the lazy solution, just catching the error and dropping that file completely since it doesnt really matter that much.
anyway, thanks for the reply!
NativeFS exists for 11.4 which is a library you can use if you want to access other places on your computer; alternatively you can wait for 12.0 which will have less strict sandboxing with love.filesystem.