Skip to content

Commit

Permalink
Twig handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Cassani committed Jun 16, 2021
1 parent c53ff9d commit 429d6ce
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Filters/Html/HtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -245,5 +276,4 @@ public function transform( $segment ) {
return $output;

}

}
20 changes: 20 additions & 0 deletions tests/MateCatSubFilteringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 &lt;3 %}';
$expected_l1_segment = '<ph id="mtc_1" equiv-text="base64:eyUgaWYgY291bnQgJmx0OzMgJX0="/>';
$expected_l2_segment = '&lt;ph id="mtc_1" equiv-text="base64:eyUgaWYgY291bnQgJmx0OzMgJX0="/&gt;';

$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;
Expand Down

0 comments on commit 429d6ce

Please sign in to comment.