View Full Version : Loading file names in file manager does not work with apostrophes

11-27-2012, 10:47 PM
So I have a file manager (similar to HFS if any of you have used it) .... Anyway when submitting ajax functions for various file actions, it doesn't work if the filenames have an apostrophe (') in them. It submits the whole part of the name up until where there's an apostrophe.

Typically to submit an ajax function it just runs something like

$.post("?mode=section&id=ajax.delete", {
filename: selectedFilesAsStr(),

Here's the javascript...

function selectedItems() { return $('#files .selector:checked') }

function selectedFilesAsStr() {
var a = [];
return a.join(":");

function getItemName(el) {
if (typeof el == 'undefined')
return false;
// we handle elements, not jquery sets
if (el.jquery)
if (el.size())
el = el[0];
return false;
// take the url, and ignore any #anchor part
var s = el.getAttribute('href') || el.getAttribute('value');
s = s.split('#')[0];
// remove protocol and hostname
var i = s.indexOf('://');
if (i > 0)
s = s.slice(s.indexOf('/',i+3));
// current folder is specified. Remove it.
if (s.indexOf(HFS.folder) == 0)
s = s.slice(HFS.folder.length);
// folders have a trailing slash that's not truly part of the name
if (s.slice(-1) == '/')
s = s.slice(0,-1);
// it is encoded
s = (decodeURIComponent || unescape)(s);
return s;
} // getItemName

Philip M
11-28-2012, 08:41 AM
Try escaping or quoting the apostrophe.

But I have to say that I think it poor practice (although not illegal) to include an apostrophe in a file name.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.