getkirby-v2 / panel

This is the deprecated admin panel for Kirby v2.
http://getkirby.com
Other
134 stars 70 forks source link

Quotes in text areas in the panel #488

Closed plison closed 9 years ago

plison commented 9 years ago

The text areas in the panel do not seem to handle quotes (both single and double) properly. When saving a text containing quotes, such as this is a "test"

the panel automatically escapes the quotes with a backslash, ie. the text becomes this is a \"test\"

However, the backslashes used for the escape are treated as normal characters once the text is saved, which means that the text now contains the backslashes (which will themselves be escaped after saving the text). Here is an example:

1) step 1 - before saving: skjermbilde 2015-05-25 kl 02 20 18

2) step 2 - after saving: skjermbilde 2015-05-25 kl 02 20 28

3) step 3: after saving a second time: skjermbilde 2015-05-25 kl 02 20 35

etc.

malvese commented 9 years ago

I just tested with a fresh Starterkit, and can't reproduce the issue. Perhaps something with Magic Quotes in your PHP config?

plison commented 9 years ago

Yes I had a closer look at it, and the problem was indeed with the Magic Quotes. Thanks for the tip! My hosting server (I use shared hosting from my university) has indeed turned on the Magic Quotes flag, and does not allow us to change this setting via .htaccess (I get a 500 error in that case).

But I found a solution, in case anyone runs into the same problem: I inserted this code in the site/config.php, and it is now working:

if (get_magic_quotes_gpc()) {
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    while (list($key, $val) = each($process)) {
        foreach ($val as $k => $v) {
            unset($process[$key][$k]);
            if (is_array($v)) {
                $process[$key][stripslashes($k)] = $v;
                $process[] = &$process[$key][stripslashes($k)];
            } else {
                $process[$key][stripslashes($k)] = stripslashes($v);
            }
        }
    }
    unset($process);
}
malvese commented 9 years ago

Nice tip! Thanks for sharing. It think it would be useful if you wrote it in the Kirby forum for future reference, in the "Solutions" category: http://forum.getkirby.com/c/solutions