file name is urlEncoded ?

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

file name is urlEncoded ?

Post by jmburnod » Sat Jan 05, 2013 10:10 am

Hi All,
What is the safest way to know if a file name is urlencoded ?
I test two ways :

Code: Select all

If "%" is in the name file  then put true into rEncoded

Code: Select all

if the file name =  item 1 of the delailedfiles then put true into rEncoded
Someone can confirm it ?
Best regards
Jean-Marc
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: file name is urlEncoded ?

Post by Mark » Sat Jan 05, 2013 12:16 pm

Hi Jean-Marc,

You can check if the file exists. A problem is that a file name might actually be URL-encoded. E.g. if a web master made a mistake and used a URL-encoded file name for a file, which was downloaded by a user who kept the name encoded. This should work:

Code: Select all

if there is a file myUrlEncodedFileName then
  put false into myUrlEncoded
else if there is a file urlDecoded(myUrlEncodedFileName) then
  put true into myUrlEncoded
else
  put "error" into myUrlEncoded
end if
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: file name is urlEncoded ?

Post by jmburnod » Sat Jan 05, 2013 6:36 pm

Hi Mark,
Thank again for help
The exists file way don't work if the filename is urlencoded, (myUrlEncoded = false)

I tried also to compare file name and item 1 of the detailed file, but it don't work if file name contains space or diacritical char.

I have added "+" to the list of chars to search in file name and it seems work with urlEncoded file name and file name that contains space or diacritical char

The stack in attachment explore the three methods

kind regards

Jean-Marc
Attachments
TestNameFileUrlEncodeOrNot.livecode.zip
(2.06 KiB) Downloaded 246 times
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: file name is urlEncoded ?

Post by Mark » Sat Jan 05, 2013 7:22 pm

Jean-Marc,

Why do you conclude that the "exists file way don't work if the filename is urlencoded"? I'd say it works.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: file name is urlEncoded ?

Post by jacque » Sat Jan 05, 2013 10:42 pm

jmburnod, there is a typo in Mark's example. Try using urlDecode() instead of "urlDecoded":

else if there is a file urlDecode(myUrlEncodedFileName) then
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: file name is urlEncoded ?

Post by jmburnod » Sat Jan 05, 2013 11:36 pm

Mark,
Why do you conclude that the "exists file way don't work if the filename is urlencoded"? I'd say it works.
i tested it and the script return false if a file name is urlencoded
Jaques,
there is a typo in Mark's example
Yes, i saw it and i corrected it in my scripts
Kind regards

Jean-Marc
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: file name is urlEncoded ?

Post by Mark » Sat Jan 05, 2013 11:55 pm

Jean-Marc,

Are you sure that your file paths are urlEncoded? Where do you get your paths from? If it returns either true or false, it means that the script works correctly because the file has been detected. If the file can't be found, e.g. because there is an error in the file path, the script returns "error". Why is there still a problem?

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: file name is urlEncoded ?

Post by jmburnod » Sun Jan 06, 2013 12:18 am

Mark,
Are you sure that your file paths are urlEncoded
Not the file path, only the last item of the file path is urlencoded (the file name).
Kind regards
Jean-marc
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: file name is urlEncoded ?

Post by Mark » Sun Jan 06, 2013 12:26 am

Hi Jean-Marc,

Either way, since you report that myUrlEncoded is false and not "error", it works. I don't understand what the problem is.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: file name is urlEncoded ?

Post by jacque » Sun Jan 06, 2013 5:16 am

I didn't check all possible encodings, but try this:

Code: Select all

function isEncoded pPath
  return not (urlDecode(pPath) = pPath)
end isEncoded
Or you may want to just test the last item of the path instead of the whole path.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: file name is urlEncoded ?

Post by jmburnod » Sun Jan 06, 2013 12:17 pm

Mark,
Either way, since you report that myUrlEncoded is false and not "error", it works. I don't understand what the problem is.
When a file name is urlencoded, myUrlEncoded = false and i don't know if I have to urldecode it to get name with diacritical and space chars.

Jacques,
Yes, this way works fine in this four cases (what else ?)
• File name with a diacritical char or space not urlEncoded: "la fée"
• File name without diacritical char or space not urlEncoded: "maison"
• File name with a diacritical char or space urlEncoded: "la+f%8Ee"
• File name without diacritical char or space urlEncoded: "maison"

Jean-Marc
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: file name is urlEncoded ?

Post by Mark » Sun Jan 06, 2013 1:21 pm

Jean-Marc,

I asked you about the source of those file names. This may make a big difference.

Can you give me an example of a case in which my script returns false (rather than "error")? It is very strange, because it means that the file exists on disk with a urlEncoded file name. Are you sure that in this case the urlEncoded file name isn't the same as the urlUnencoded filename, because the filename has no special chars?

Jacque's solution won't work. For example, if your actual filename contains a +, her approach will report that the filename is encoded. You could take care of all peculiarities by checking for each special character, but it is much easier to simply check that the file exists.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: file name is urlEncoded ?

Post by jmburnod » Sun Jan 06, 2013 1:45 pm

Hi mark,

You're right for the "+" case
Can you give me an example of a case in which my script returns false (rather than "error")?
Yes, a file "f%8Ee_1.png" return false
Are you sure that in this case the urlEncoded file name isn't the same as the urlUnencoded filename, because the filename has no special chars?
Yes, urldecode("f%8Ee_1.png") = "fée_1.png"

Kind regards
Jean-Marc
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: file name is urlEncoded ?

Post by Mark » Sun Jan 06, 2013 2:53 pm

Jean-Marc,

You still haven't explained where you file names come from. One way or another, LiveCode must receive a list of urlEncoded file names. As long as you don't tell me the source of this list, I can't do any more for you.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: file name is urlEncoded ?

Post by jmburnod » Sun Jan 06, 2013 3:59 pm

Hi Mark,
Files come from my iPad
Kind regards
Jean-Marc
https://alternatic.ch

Post Reply