Page 1 of 1
urlencode() mystery
Posted: Sat Oct 24, 2015 6:19 pm
by jmburnod
Hi All,
I have to use urlencode function to keep accented letters in file name.
I get different results with file name "zéro.png" in these contexts
1. Typing "zéro.png" with keyboard.
urlencode("zéro.png") return "z%8Ero.png"
2. Get the file name by answer file
urlencode("zéro.png") return "ze%3Fro.png"
I tested : nameFile = nametypedwithkeyboard with casesensitive = true
Any idea ?
Best regards
Jean-Marc
Re: urlencode() mystery
Posted: Sun Oct 25, 2015 10:08 am
by scrabbles
hi, might be a bug? i think both are incorrect, shouldn't it be z%E9ro.png. Using other langs or online urlencoders, i get z%C3%A9ro.png.
— Mark
Re: urlencode() mystery
Posted: Sun Oct 25, 2015 5:09 pm
by jacque
If you are using LC 7 it's probably the difference between the OS unicode format and LC's format. After you get the filename from the answer file dialog, put it through textDecode first before using urlEncode. See if that helps.
Re: urlencode() mystery
Posted: Sun Oct 25, 2015 5:14 pm
by Klaus
So much for "Unicode, it just works!"

Re: urlencode() mystery
Posted: Sun Oct 25, 2015 5:55 pm
by jacque
It's just how operating systems work. They all use different encodings, so you have to convert from the OS encoding to LC UTF16.
But I agree file names should be converted automatically the same way line endings are. If textDecode works then it could be a bug. If textDecode doesn't work then the problem may not be unicode translation. LC has had problems with unicode file names in the past.
Re: urlencode() mystery
Posted: Sun Oct 25, 2015 6:40 pm
by jmburnod
Thanks All,
I tried this but it doesn't work for me. Where I'm wrong ?
Code: Select all
on mouseUp
answer file "open file :"--name of selected file = "zéro.png"
set the itemdel to "/"
put item -1 of it into tName
set the itemdel to ","
put textdecode(tName,"UTF-8") into tEncodeName --return "zro.png"
dansmes urlencode(tEncodeName)--return "zro.png"
end mouseUp
Jean-Marc
Re: urlencode() mystery
Posted: Sun Oct 25, 2015 8:32 pm
by jacque
The OS encoding may not be UTF8, it's probably native. Use this instead:
put textdecode(tName,"Native") into tEncodeName
The engine will look for the correct encoding for the OS. But I am not completely sure that unicode decoding is the problem, so this is just a test to see if it works. What OS are you running?
Re: urlencode() mystery
Posted: Sun Oct 25, 2015 11:41 pm
by jmburnod
Thanks one more Jaques,
"Native" seems the magic word
Code: Select all
put textdecode(tName,"Native") into tEncodeName --return "zéro.png"
I tried also UTF-16 that return chinese chars
Code: Select all
put textdecode(tName,"UTF-16") into tEncodeName --return "蹺潲瀮杮"
What OS are you running?
OS X 10.10.3
Best regards
Jean-Marc