From 8f2776bc46a55e5b6f712bfaa662d2e30a98491d Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 15 Mar 2022 13:47:46 -0700 Subject: [PATCH] Linkwords: Ignore commented HTML code during processing. --- e107_plugins/linkwords/e_parse.php | 14 +++++++++++--- .../plugins/linkwords/e_tohtml_linkwordsTest.php | 13 +++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/e107_plugins/linkwords/e_parse.php b/e107_plugins/linkwords/e_parse.php index 8b222d8b0..b10e245dd 100644 --- a/e107_plugins/linkwords/e_parse.php +++ b/e107_plugins/linkwords/e_parse.php @@ -233,6 +233,7 @@ class linkwords_parse // Split up by HTML tags and process the odd bits here $ptext = ""; $lflag = FALSE; + $cflag = false; // commented code prsent. // Shouldn't need utf-8 on next line - just looking for HTML tags $content = preg_split('#(<.*?>)#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); @@ -241,12 +242,19 @@ class linkwords_parse foreach($content as $cont) { + if(strpos($cont, '-->') !== false) + { + $cflag = false; // end of commented code + $ptext .= $cont; + continue; + } if ($cont[0] === "<") // Its some HTML { $ptext .= $cont; - if (strpos($cont, "area_opts['TITLE'])) // disable linking on header tag content unless enabled in prefs. { @@ -263,7 +271,7 @@ class linkwords_parse } else // Its the text in between { - if ($lflag) // Its probably within a link - leave unchanged + if ($lflag || $cflag) // Its probably within a link - leave unchanged { $ptext .= $cont; } diff --git a/e107_tests/tests/unit/plugins/linkwords/e_tohtml_linkwordsTest.php b/e107_tests/tests/unit/plugins/linkwords/e_tohtml_linkwordsTest.php index a4636ab28..0739ecad5 100644 --- a/e107_tests/tests/unit/plugins/linkwords/e_tohtml_linkwordsTest.php +++ b/e107_tests/tests/unit/plugins/linkwords/e_tohtml_linkwordsTest.php @@ -81,13 +81,22 @@ 'text' => "

Body only title

body only text

", 'expected' => "

Body only title

body only text

", ), + // Ignore commented code. + 6 => array( + 'text' => "

body only text

", + 'expected' => "

body only text

", + ), + 7 => array( + 'text' => "contact us link

body only text

", + 'expected' => 'contact us link

body only text

', + ), ); - foreach($tests as $val) + foreach($tests as $index => $val) { $result = $this->lw->toHTML($val['text'], 'BODY'); - $this->assertEquals($val['expected'],$result); + $this->assertEquals($val['expected'],$result, 'Test #'.$index.' failed. '); }