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
Code:
$.post("?mode=section&id=ajax.delete", {
filename: selectedFilesAsStr(),
});
Here's the javascript...
Code:
function selectedItems() { return $('#files .selector:checked') }
function selectedFilesAsStr() {
var a = [];
selectedItems().each(function(){
a.push(getItemName(this));
});
return a.join(":");
}//selectedFilesAsStr
function getItemName(el) {
if (typeof el == 'undefined')
return false;
// we handle elements, not jquery sets
if (el.jquery)
if (el.size())
el = el[0];
else
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