Setting url of browser widget, incompatible characters

Trevor DeVore lists at mangomultimedia.com
Wed Mar 23 09:11:21 EDT 2016


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



More information about the use-livecode mailing list