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 ...@@ -67,10 +67,13 @@ abstract class TyposClientInterface
* @param string $context Context where the typo found * @param string $context Context where the typo found
* @param TyposArticle $article Article to fix the typo * @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 // Strip all tags from text
$text = strip_tags($article->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 // Find all typos in text, capture an offset of each typo
$typos = []; $typos = [];
preg_match_all("#{$typo}#", $text, $typos, PREG_OFFSET_CAPTURE); preg_match_all("#{$typo}#", $text, $typos, PREG_OFFSET_CAPTURE);
...@@ -80,14 +83,12 @@ abstract class TyposClientInterface ...@@ -80,14 +83,12 @@ abstract class TyposClientInterface
$contextMatch = []; $contextMatch = [];
preg_match_all("#{$context}#", $text, $contextMatch, PREG_OFFSET_CAPTURE); preg_match_all("#{$context}#", $text, $contextMatch, PREG_OFFSET_CAPTURE);
error_log("Context match = " . print_r($contextMatch, true));
$contextMatch = $contextMatch[0]; $contextMatch = $contextMatch[0];
if (!isset($contextMatch[0])) { if (!isset($contextMatch[0])) {
throw new \Exception("Failed to find the context in article"); throw new \Exception("Failed to find the context in article");
} }
$contextOffset = $contextMatch[0][1]; $contextOffset = $contextMatch[0][1];
// Find a concrete typo that we want to fix // 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