Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] escape language strings double quotes #5907

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion libraries/joomla/language/language.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
}