Issue Bug Closed

#29067Encoding UTF-8 in unescape function

Rafał Wójcik 08/18/11, 08:30 updated 10/24/17, 20:18

Description

The best way to understand bug is look for video:
http://www.screencast-o-matic.com/watch/cXjbju3fU [^]

I solve problem in my typo3 version but I think that not only I have this problem.

SOLVE:
– file: t3lib/class.t3lib_tceforms.php:
line: 2799

change:

$onClickInsert .= 'new Insertion.Bottom($("' . $idTagPrefix . '"), unescape("' . rawurlencode($newElementTemplate) . '").' . $replace . '); setActionStatus("' . $idTagPrefix . '");';

to:

$onClickInsert .= 'new Insertion.Bottom($("' . $idTagPrefix . '"), utf8_decode(unescape("' . rawurlencode($newElementTemplate) . '")).' . $replace . '); setActionStatus("' . $idTagPrefix . '");';

and add somwhere JS function:

function utf8_decode (utftext) {
    var string = ""; var i = 0; var c = c1 = c2 = 0;
    while ( i < utftext.length ) {
        c = utftext.charCodeAt(i);
        if (c < 128) { string += String.fromCharCode(c); i++; }
        else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; }
        else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; }
    }
    return string;
}

Sorry form my poor english :)

Reviews 5