local filename = ""
function unescape (s)
s = string.gsub(s, "+", " ")
s = string.gsub(s, "%%(%x%x)", function (h)
return string.char(tonumber(h, 16))
end)
return s
end
function love.filedropped(file)
filename = file:getFilename()
end
function love.draw()
love.graphics.print("Original: " .. filename, 10, 10)
love.graphics.print("Unescaped: " .. unescape(filename), 10, 30)
end
Well your solution is good, but this is a problem with your file manager, and you should be careful with this solution, because I could have a file called Let%C3%B6lt%C3%A9sek and your solution would turn this into Letöltések (I think) which is something I don't expect. Basically the inverse to your problem.
By covering an edge case you create another, so the best solution would either be to make this a configuration option or don't depend on it... Also reporting the "error" (may be intended behaviour though) to the developers of the file manager may be a good idea, I don't know
for i, person inipairs(everybody) do [tab]ifnot person.obey then person:setObey(true) end end
love.system.openURL(github.com/pablomayobre)
raidho36 wrote:Does it escapes any unicode strings or just file paths?
I don't know, I was testing this through love.filedropped() and file:getFilename().
Test it then, just to be sure.
easy82 wrote:
zorg wrote:To me, what's interesting is that not only the text is encoded as UTF-8, but it's not plainly UTF-8, but rather, escaped per-character with %-s like html; very strange.
Do you know any good way to unescape this string in LUA?
It can be done, but i don't know whether that's a solution, and not just a workaround...
string.gsub(filename, "(%%)([0-9a-fA-F])", "%2") -- untested, but should work.
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.
Positive07 wrote:Well your solution is good, but this is a problem with your file manager, and you should be careful with this solution, because I could have a file called Let%C3%B6lt%C3%A9sek and your solution would turn this into Letöltések (I think) which is something I don't expect. Basically the inverse to your problem.
By covering an edge case you create another, so the best solution would either be to make this a configuration option or don't depend on it... Also reporting the "error" (may be intended behaviour though) to the developers of the file manager may be a good idea, I don't know
I see your point...!
zorg wrote:It can be done, but i don't know whether that's a solution, and not just a workaround...
Yes it's just a workaround.
Do you guys think this is a bug that I should report?
So some file managers escape Unicode and some don't. I assume that has to do with file:// protocol which is allowed to escape non ASCII characters, or in fact any characters. What I think is proper solution is for LÖVE to unescape file paths internally before output.
function love.filedropped(file)
local file = love.filesystem.newFile(file:getFilename():gsub("+"," "):gsub("%%(%x%x)",function (h)
return string.char(tonumber(h, 16))
end))
local ok, err = file:open("r")
if not ok then
print(err)
return
end
local data = file:read()
file:close()
end
Also, earlier you wrote "/home/user/Let%F6lt%E9sek/test.txt", using singular escaped chars (meaning the encoding was not utf-8 but some 8-bit codepage (Latin-2 or equivalent), but later, positive07 wrote "Let%C3%B6lt%C3%A9sek", which was the escaped utf-8 encoding. Technically those two are separate issues, would be nice to know whether the second case also happens, or not.
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.