diff --git a/src/Filters/Html/HtmlParser.php b/src/Filters/Html/HtmlParser.php index 287baa1..18cd9e7 100644 --- a/src/Filters/Html/HtmlParser.php +++ b/src/Filters/Html/HtmlParser.php @@ -179,6 +179,37 @@ public function transform( $segment ) { break; default: + + // Check the last char + if($idx === (count($originalSplit)-1)){ + + $html_buffer .= $char; + + // + // ************************************* + // NOTE 2021-06-16 + // ************************************* + // + // Check if $html_buffer is valid. If not, then + // convert it to $plain_text_buffer. + // + // Example: + // + // $html_buffer = '<3 %}' + // + // is not a valid tag, so it's converted to $plain_text_buffer + // + if(!$this->_isTagValid( $html_buffer )){ + $state = static::STATE_PLAINTEXT; // but we work in XML text, so encode it + $plain_text_buffer .= $this->_fixWrongBuffer( $html_buffer ); + $html_buffer = ''; + + break; + } + + break; + } + $html_buffer .= $char; break; } @@ -245,5 +276,4 @@ public function transform( $segment ) { return $output; } - } diff --git a/tests/MateCatSubFilteringTest.php b/tests/MateCatSubFilteringTest.php index ab33fe9..8478bd8 100644 --- a/tests/MateCatSubFilteringTest.php +++ b/tests/MateCatSubFilteringTest.php @@ -269,6 +269,26 @@ public function testTwigFilterWithLessThan() $this->assertEquals($db_segment, $back_to_db); } + public function testTwigFilterWithLessThanAttachedToANumber() + { + // less than %lt; + $Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] ); + + $db_segment = '{% if count <3 %}'; + $expected_l1_segment = ''; + $expected_l2_segment = '<ph id="mtc_1" equiv-text="base64:eyUgaWYgY291bnQgJmx0OzMgJX0="/>'; + + $l1_segment = $Filter->fromLayer0ToLayer1( $db_segment ); + $l2_segment = $Filter->fromLayer1ToLayer2( $l1_segment ); + + $this->assertEquals($l1_segment, $expected_l1_segment); + $this->assertEquals($l2_segment, $expected_l2_segment); + + $back_to_db = $Filter->fromLayer1ToLayer0($expected_l1_segment); + + $this->assertEquals($db_segment, $back_to_db); + } + public function testTwigFilterWithGreaterThan() { // less than %gt;