jstranger
Posts: 15
Joined: Thu Nov 11, 2010 12:09 pm

Image file names containing ampersand

I have a number of image files with filenames that include special characters - notably ampersand. In order to get Highslide to handle such file names, my code uses the .NET Uri.EscapeUriString or EscapeDataString utilities to escape such characters. As well as e.g. converting spaces to %20, etc., the second of these utilities converts an ampersand to %26 while the first leaves it as &. In both cases, I can copy and paste the generated url from a View Source window to a browser address box and see the image. So I have to assume that for some reason Highslide either cannot handle such characters or does some form of additional conversion which causes the final url to be invalid.

I suspect that there is a similar issue with filenames containing single apostrophes, but am still investigating that.

Is there a recognised way of dealing with this issue or do I have to rename all my image files (ugh!)?

Jon
MisterNeutron
Posts: 440
Joined: Sun Aug 18, 2013 11:20 am

Re: Image file names containing ampersand

Please give us a link to a "problem" page.

But a few thoughts, in no particular order....
  • Highslide JS certainly isn't trying to do any character conversion. Look through the code yourself, and you won't find anything in there relating to it.
  • A file name should work in all browsers without any escaping. It won't pass validation, but it won't fail, either. So, a file name of Black & White.jpg is OK. On the other hand, It will work, and will validate, if it's encoded as Black%20%26%20White.jpg.
  • Don't rely on a copied-and-pasted link from a View Source window. At that point, the browser may have already "fixed" a problem link.
  • A file name with a single quote (apostrophe) will be a problem if you use single quotes in your HTML. In other words, if you routinely use <a href='image.jpg'> instead of <a href="image.jpg">, then the single quotes will need to be escaped.
  • Ampersands and single quotes in file names are not "web safe," and should not be used, along with a number of other characters. See http://tools.ietf.org/html/rfc3986#section-2 for a list of reserved characters. Avoid future troubles, and fix the file names.
jstranger
Posts: 15
Joined: Thu Nov 11, 2010 12:09 pm

Re: Image file names containing ampersand

Many thanks for the rapid and considered response.

I am afraid that I can't easily give a link to a problem page as this app is not public yet, but will see if I can put together something comparable. Although, assuming that you are correct and that the browser is somehow correcting broken code and View Source is unreliable, I am not sure what this will achieve.

Re. single apostrophe, I did have a suspicion that this was related to string termination rather than non-safe characters, So will check my code carefully (although again the generated urls in View Source seem OK).

But otherwise I guess I will have to do as you suggest as rename a lot of files - which since they originate from another (non-Web) app will be a pain.
MisterNeutron
Posts: 440
Joined: Sun Aug 18, 2013 11:20 am

Re: Image file names containing ampersand

It's sometimes a real struggle to convince users not to give files names like:

What's up with cats & dogs?!!... ["#3"].jpg

;)

Return to “Highslide JS Usage”