From 7ae3b1d3991f2c605f4f5742e28780e218689250 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Wed, 3 Aug 2022 16:27:21 +0300 Subject: [PATCH] fix cleaning of string content --- .../com_jedchecker/libraries/helper.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_jedchecker/libraries/helper.php b/administrator/components/com_jedchecker/libraries/helper.php index b6ad54e..3a61ef5 100644 --- a/administrator/components/com_jedchecker/libraries/helper.php +++ b/administrator/components/com_jedchecker/libraries/helper.php @@ -303,7 +303,7 @@ abstract class JEDCheckerHelper { if (!$parse) { - return str_repeat("\n", substr_count($content, "\n")); + return self::cleanLines($content); } $pos = 0; @@ -312,7 +312,7 @@ abstract class JEDCheckerHelper while (preg_match('/\n|\\\\|\{\$|\$\{/', $content, $match, PREG_OFFSET_CAPTURE, $pos)) { $foundPos = $match[0][1]; - $cleanContent .= substr($content, $pos, $foundPos - $pos); + $cleanContent .= self::cleanLines(substr($content, $pos, $foundPos - $pos)); $pos = $foundPos; switch ($match[0][0]) @@ -384,4 +384,17 @@ abstract class JEDCheckerHelper return $cleanContent; } + + /** + * Remove all content except of EOLs to preserve line numbers + * + * @param string $content + * + * @return string + * @since 2.4.2 + */ + protected static function cleanLines($content) + { + return str_repeat("\n", substr_count($content, "\n")); + } }