Commit f24c5ecb authored by Jorgen's avatar Jorgen

Add preg_quote invokation to secure input data

parent 308b40b8
......@@ -67,10 +67,13 @@ abstract class TyposClientInterface
* @param string $context Context where the typo found
* @param TyposArticle $article Article to fix the typo
*/
public function replaceTypoInArticle(string $typo, string $corrected, string $context, TyposArticle $article) {
public function replaceTypoInArticle(string $typo, string $corrected, string $context, TyposArticle $article) {
// Strip all tags from text
$text = strip_tags($article->text);
$context = preg_quote($context);
$typo = preg_quote($typo);
// Find all typos in text, capture an offset of each typo
$typos = [];
preg_match_all("#{$typo}#", $text, $typos, PREG_OFFSET_CAPTURE);
......@@ -80,14 +83,12 @@ abstract class TyposClientInterface
$contextMatch = [];
preg_match_all("#{$context}#", $text, $contextMatch, PREG_OFFSET_CAPTURE);
error_log("Context match = " . print_r($contextMatch, true));
$contextMatch = $contextMatch[0];
if (!isset($contextMatch[0])) {
throw new \Exception("Failed to find the context in article");
}
$contextOffset = $contextMatch[0][1];
// Find a concrete typo that we want to fix
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment