urlencode() mystery

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

urlencode() mystery

Post by jmburnod » Sat Oct 24, 2015 6:19 pm

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
https://alternatic.ch

scrabbles
Posts: 25
Joined: Sat Dec 20, 2014 4:32 am
Location: Melbourne, Australia

Re: urlencode() mystery

Post by scrabbles » Sun Oct 25, 2015 10:08 am

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: urlencode() mystery

Post by jacque » Sun Oct 25, 2015 5:09 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: urlencode() mystery

Post by Klaus » Sun Oct 25, 2015 5:14 pm

So much for "Unicode, it just works!" :D

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: urlencode() mystery

Post by jacque » Sun Oct 25, 2015 5:55 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: urlencode() mystery

Post by jmburnod » Sun Oct 25, 2015 6:40 pm

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
https://alternatic.ch

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: urlencode() mystery

Post by jacque » Sun Oct 25, 2015 8:32 pm

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?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: urlencode() mystery

Post by jmburnod » Sun Oct 25, 2015 11:41 pm

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
https://alternatic.ch

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”