Setting url of browser widget, incompatible characters

Tore Nilsen tore.nilsen at me.com
Wed Mar 23 09:18:40 EDT 2016


Thank you this is very useful. As file names can also contain other characters that may be changed during urlEncoding I will have to experiment to take them into consideration as well. From what I can see I will need to convert apostrophes, parenthesises and commas back to their original characters. 


Tore


> 23. mar. 2016 kl. 14.11 skrev Trevor DeVore <lists at mangomultimedia.com>:
> 
> On Wed, Mar 23, 2016 at 8:30 AM, Tore Nilsen <tore.nilsen at me.com> wrote:
> 
>> It did not work. URLEncode also encodes “/“  to %2 and spaces to + as you
>> can see:
>> 
>> file://%2FUsers%2Ftorenilsen%2FDocuments%2FMultimedieLab%2FMusikk%2F01+My+My%2C+Hey+Hey+%28Out+of+the+Blue%29.m4p
>> 
> 
> This is a function I use to convert filenames into file urls.
> 
> /**
> * \brief Converts a LiveCode filename to a file url.
> *
> * \param pFilename The filename to convert.
> *
> * Each item of the filename will be escaped and "file://" will be prefixed.
> *
> * \return File url.
> */
> function fileConvertToFileURL pFilename
>   local theItem, i
> 
>   set the itemDelimiter to "/"
> 
>   repeat with i = 1 to the number of items of pFilename
>      put item i of pFilename into theItem
>      if i is 1 AND theItem contains ":" then next repeat # skip C:/
> 
>      put URLEncode(theItem) into theItem
>      replace "+" with "%20" in theItem
>      replace "*" with "%2A" in theItem
>      put theItem into item i of pFilename
>   end repeat
> 
>   # [case 1] Windows C:/ paths need to start with a "//"
>   # [case 2] If path starts with "//" then it is a network path. Add
>   # an extra "/" so that domain is considered localhost.
>   if char 1 of pFilename is not "/" then
>      put "/" before pFilename
>   else if pFilename begins with "//" then
>      delete char 1 to 2 of pFilename
>   end if
> 
>   return "file://" & pFilename
> end fileConvertToFileURL
> 
> -- 
> Trevor DeVore
> ScreenSteps
> www.screensteps.com    -    www.clarify-it.com
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list