From 774e65dcb9c849233a6fab745c4b1636cd1deec0 Mon Sep 17 00:00:00 2001 From: Roberto Segura - phproberto Date: Wed, 28 Jan 2015 13:46:44 +0100 Subject: [PATCH] [fix] escape language strings double quotes --- libraries/joomla/language/language.php | 32 +++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/language/language.php b/libraries/joomla/language/language.php index a161f76c3249e..220f7dedb7b79 100644 --- a/libraries/joomla/language/language.php +++ b/libraries/joomla/language/language.php @@ -842,7 +842,9 @@ protected function parse($filename) } $contents = file_get_contents($filename); - $contents = str_replace('_QQ_', '"\""', $contents); + + $contents = $this->prepareContents($contents); + $strings = @parse_ini_string($contents); if (!is_array($strings)) @@ -1404,4 +1406,32 @@ public static function parseXMLLanguageFile($path) return $metadata; } + + /** + * Callback for preg_replace_callback to escape double quotes inside language strings. + * + * @param array $matches Array of strings that match with the regular expression + * + * @return string + * + * @since 3.4 + */ + private function escapeContentsQuotes($matches) + { + return '"' . str_replace('"', '\"', $matches[1]) . '"'; + } + + /** + * Sanitize / prepare contents to be used by parse_ini_string. + * + * @param string $contents String containing the contents to prepare + * + * @return string + * + * @since 3.4 + */ + protected function prepareContents($contents) + { + return preg_replace_callback('/"(.*)"/', array($this, 'escapeContentsQuotes'), $contents); + } }