Filebrowser: properly escape JS config options

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Filebrowser: properly escape JS config options

Post by cmb » Mon Jul 14, 2014 8:55 pm

Hello Community,

I've just stumbled upon some help texts of the filebrowser, e.g.

Code: Select all

$plugin_tx['filebrowser']['cf_confirm_delete']="This text is used in javascript context: Do not use \" or '";
IMO it is ridiculous to tell users to eschew some characters instead of the software using proper escaping, when necessary. In this case the following might already suffice:

Code: Select all

addcslashes($string, '\\"')
Christoph
Christoph M. Becker – Plugins for CMSimple_XH

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Filebrowser: properly escape JS config options

Post by cmb » Thu Jan 01, 2015 11:00 pm

I had a closer look at the issue. The problem is that the three respective language strings are used as literal JS strings inside event handler attributes, e.g. (simplified)

Code: Select all

onsubmit="return confirm('Really delete?')"
So here we would have to escape the special HTML characters as HTML entities and apostrophes as \' (' is not valid under HTML 4.01). If there was no string literal, we wouldn't have to escape apostrophes, and could simple use XH_hsc() (if that was available in the editorbrowser. ;)).

So for now I've implemented a manual escaping (r1434).

For XH 1.7 we should really clean that up, though, and avoid using string literals in event handler attributes (or even event handler attributes at all). The language strings could be defined as properties of the FILEBROWSER object (escaped with json_encode()), and the actual filenames can be read from the adjacent elements -- that saves some bandwidth and the quoting hell.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply