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?
UTF-8 decoding issue
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- slime
- Solid Snayke
- Posts: 3172
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: UTF-8 decoding issue
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.
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
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!
anyway, thanks for the reply!
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: UTF-8 decoding issue
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.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!
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: Ahrefs [Bot], Hydrogen Maniac and 3 guests