From: Alexander Ebert Date: Mon, 15 Apr 2013 12:15:20 +0000 (+0200) Subject: Fixed usernames with apostrophes X-Git-Tag: 2.0.0_Beta_1~355 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5d502a6465d76ba34b2f52edf672fbae8ead8cc0;p=GitHub%2FWoltLab%2FWCF.git Fixed usernames with apostrophes --- diff --git a/wcfsetup/install/files/lib/system/template/plugin/EncodeJSONModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/EncodeJSONModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..1ceaee0af3 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/EncodeJSONModifierTemplatePlugin.class.php @@ -0,0 +1,28 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class EncodeJSONModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\IModifierTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + return StringUtil::encodeJSON($tagArgs[0]); + } +} diff --git a/wcfsetup/install/files/lib/util/StringUtil.class.php b/wcfsetup/install/files/lib/util/StringUtil.class.php index 90f7b4a546..6e4198861a 100644 --- a/wcfsetup/install/files/lib/util/StringUtil.class.php +++ b/wcfsetup/install/files/lib/util/StringUtil.class.php @@ -106,6 +106,21 @@ final class StringUtil { return $string; } + /** + * Encodes JSON strings. This is not the same as PHP's json_encode()! + * + * @param string $string + * @return string + */ + public static function encodeJSON($string) { + $string = self::encodeJS($string); + + // single quotes must be encoded as HTML entity + $string = self::replace("\'", "'", $string); + + return $string; + } + /** * Decodes html entities. *