Skip to content

Commit

Permalink
Removed block of variables included in single curly brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Cassani committed Jun 4, 2021
1 parent 834a4e8 commit 3806072
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/Filters/TwigToPh.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TwigToPh extends AbstractHandler {
* @return string
*/
public function transform( $segment ) {
preg_match_all( '/{{[^<>]+?}}|{%[^<>]+?%}|{#[^<>]+?#}|{[^<>]+?}/', $segment, $html, PREG_SET_ORDER );
preg_match_all( '/{{[^<>]+?}}|{%[^<>]+?%}|{#[^<>]+?#}/', $segment, $html, PREG_SET_ORDER );
foreach ( $html as $pos => $twig_variable ) {
//check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag
if( !strstr($twig_variable[0], Constants::GTPLACEHOLDER) ){
Expand Down
43 changes: 11 additions & 32 deletions tests/MateCatSubFilteringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,6 @@ public function testComplexXML()

}

// /**
// * Filters BUG, segmentation on HTML ( Should be fixed, anyway we try to cover )
// * @throws \Exception
// */
// public function testComplexBrokenHtmlInXML()
// {
// $filter = $this->getFilterInstance();
//
// $segment = '%{abb:flag.nolinkvalidation[0]} &lt;div class="panel"&gt; &lt;div class="panel-body"&gt; &lt;p&gt;You can read this article in &lt;a href="/help/article/1381?';
// $segmentL1 = $filter->fromLayer0ToLayer1( $segment );
// $segmentL2 = $filter->fromLayer0ToLayer2( $segment );
//
// $this->assertEquals( $segment, $filter->fromLayer1ToLayer0( $segmentL1 ) );
//
// $string_from_UI = '<ph id="mtc_1" equiv-text="base64:JXthYmI6ZmxhZy5ub2xpbmt2YWxpZGF0aW9uWzBdfQ=="/> <ph id="mtc_2" equiv-text="base64:Jmx0O2RpdiBjbGFzcz0icGFuZWwiJmd0Ow=="/> <ph id="mtc_3" equiv-text="base64:Jmx0O2RpdiBjbGFzcz0icGFuZWwtYm9keSImZ3Q7"/> <ph id="mtc_4" equiv-text="base64:Jmx0O3AmZ3Q7"/>You can read this article in &lt;a href="/help/article/1381?';
//
// $this->assertEquals( $segment, $filter->fromLayer2ToLayer0( $string_from_UI ) );
// $this->assertEquals( $segmentL2, $filter->fromLayer1ToLayer2( $segmentL1 ) );
// $this->assertEquals( $segmentL1, $filter->fromLayer2ToLayer1( $string_from_UI ) );
//
// }

/**
* @throws \Exception
*/
Expand Down Expand Up @@ -243,16 +221,6 @@ public function test_3_HandlingNBSP()
public function testHTMLFromLayer2()
{
$filter = $this->getFilterInstance();

//Original JSON value from Airbnb
//"&lt;br>&lt;br>This will "

//Xliff Value
//"&amp;lt;br&gt;&amp;lt;br&gt;This will "

//Fixed by airbnb plugin in Database
//"&lt;br&gt;&lt;br&gt;This will"

$expected_segment = '&lt;b&gt;de %1$s, &lt;/b&gt;que';

//Start test
Expand All @@ -275,6 +243,17 @@ public function testSprintf()
$this->assertEquals( $segment, $seg_transformed );
}

public function testTwigFilterWithSingleBrackets()
{
$segment = 'Hi {this strings would not be escaped}. Instead {{this one}} is a valid twig expression. Also {%%ciao%%} is valid!';
$expected = 'Hi {this strings would not be escaped}. Instead <ph id="mtc_1" equiv-text="base64:e3t0aGlzIG9uZX19"/> is a valid twig expression. Also <ph id="mtc_2" equiv-text="base64:eyUlY2lhbyUlfQ=="/> is valid!';

$channel = new Pipeline();
$channel->addLast( new TwigToPh() );
$seg_transformed = $channel->transform( $segment );
$this->assertEquals( $expected, $seg_transformed );
}

public function testTwigUngreedy()
{
$segment = 'Dear {{customer.first_name}}, This is {{agent.alias}} with Airbnb.';
Expand Down

0 comments on commit 3806072

Please sign in to comment.