Page 1 of 2
file name is urlEncoded ?
Posted: Sat Jan 05, 2013 10:10 am
by jmburnod
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
Re: file name is urlEncoded ?
Posted: Sat Jan 05, 2013 12:16 pm
by Mark
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
Re: file name is urlEncoded ?
Posted: Sat Jan 05, 2013 6:36 pm
by jmburnod
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
Re: file name is urlEncoded ?
Posted: Sat Jan 05, 2013 7:22 pm
by Mark
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
Re: file name is urlEncoded ?
Posted: Sat Jan 05, 2013 10:42 pm
by jacque
jmburnod, there is a typo in Mark's example. Try using urlDecode() instead of "urlDecoded":
else if there is a file urlDecode(myUrlEncodedFileName) then
Re: file name is urlEncoded ?
Posted: Sat Jan 05, 2013 11:36 pm
by jmburnod
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
Re: file name is urlEncoded ?
Posted: Sat Jan 05, 2013 11:55 pm
by Mark
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
Re: file name is urlEncoded ?
Posted: Sun Jan 06, 2013 12:18 am
by jmburnod
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
Re: file name is urlEncoded ?
Posted: Sun Jan 06, 2013 12:26 am
by Mark
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
Re: file name is urlEncoded ?
Posted: Sun Jan 06, 2013 5:16 am
by jacque
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.
Re: file name is urlEncoded ?
Posted: Sun Jan 06, 2013 12:17 pm
by jmburnod
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
Re: file name is urlEncoded ?
Posted: Sun Jan 06, 2013 1:21 pm
by Mark
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
Re: file name is urlEncoded ?
Posted: Sun Jan 06, 2013 1:45 pm
by jmburnod
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
Re: file name is urlEncoded ?
Posted: Sun Jan 06, 2013 2:53 pm
by Mark
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
Re: file name is urlEncoded ?
Posted: Sun Jan 06, 2013 3:59 pm
by jmburnod
Hi Mark,
Files come from my iPad
Kind regards
Jean-Marc