diff --git a/src/Filters/SubFilteredPhToHtml.php b/src/Filters/SubFilteredPhToHtml.php index d3ac06b..01f8efe 100644 --- a/src/Filters/SubFilteredPhToHtml.php +++ b/src/Filters/SubFilteredPhToHtml.php @@ -10,7 +10,6 @@ namespace Matecat\SubFiltering\Filters; use Matecat\SubFiltering\Commons\AbstractHandler; -use Matecat\SubFiltering\Commons\Constants; class SubFilteredPhToHtml extends AbstractHandler { @@ -25,7 +24,6 @@ public function transform( $segment ){ preg_match_all( '||siU', $segment, $html, PREG_SET_ORDER ); // Ungreedy foreach ( $html as $subfilter_tag ) { $value = base64_decode( $subfilter_tag[ 1 ] ); - $value = html_entity_decode( $value, ENT_NOQUOTES | ENT_XML1 ); $segment = str_replace( $subfilter_tag[0], $value, $segment ); } diff --git a/tests/MateCatSubFilteringTest.php b/tests/MateCatSubFilteringTest.php index c643eb4..4343b02 100644 --- a/tests/MateCatSubFilteringTest.php +++ b/tests/MateCatSubFilteringTest.php @@ -679,4 +679,43 @@ public function testPhTagsWithoutDataRef() $this->assertEquals($back_to_db_segment, $db_segment); } + + public function testXTags() + { + $Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] ); + + $db_segment = '<x id="3"/>Primary Care Facilities<x id="7"/>'; + $expected_l1_segment = 'Primary Care Facilities'; + $expected_l2_segment = '<ph id="mtc_1" equiv-text="base64:Jmx0O3ggaWQ9IjMiLyZndDs="/>Primary Care Facilities<ph id="mtc_2" equiv-text="base64:Jmx0O3ggaWQ9IjciLyZndDs="/>'; + + $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_segment = $Filter->fromLayer1ToLayer0($l1_segment); + + $this->assertEquals($back_to_db_segment, $db_segment); + } + + public function testWithComplexUrls() + { + $Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] ); + + $db_segment = '<li>Bergamo: <a href="http://www.comune.bergamo.it/servizi/Menu/dinamica.aspx?idSezione=3780&#38;idArea=1182&#38;idCat=555&#38;ID=28395&#38;TipoElemento=categoria" target="_blank">Italian</a> </li> 󠄀'; + $expected_l1_segment = 'Bergamo: Italian 󠄀'; + $expected_l2_segment = '<ph id="mtc_1" equiv-text="base64:Jmx0O2xpJmd0Ow=="/>Bergamo: <ph id="mtc_2" equiv-text="base64:Jmx0O2EgaHJlZj0iaHR0cDovL3d3dy5jb211bmUuYmVyZ2Ftby5pdC9zZXJ2aXppL01lbnUvZGluYW1pY2EuYXNweD9pZFNlemlvbmU9Mzc4MCZhbXA7IzM4O2lkQXJlYT0xMTgyJmFtcDsjMzg7aWRDYXQ9NTU1JmFtcDsjMzg7SUQ9MjgzOTUmYW1wOyMzODtUaXBvRWxlbWVudG89Y2F0ZWdvcmlhIiB0YXJnZXQ9Il9ibGFuayImZ3Q7"/>Italian<ph id="mtc_3" equiv-text="base64:Jmx0Oy9hJmd0Ow=="/> <ph id="mtc_4" equiv-text="base64:Jmx0Oy9saSZndDs="/>##$_0A$##󠄀'; + + $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_segment = $Filter->fromLayer1ToLayer0($l1_segment); + + $this->assertEquals($back_to_db_segment, $db_segment); + + } } \ No newline at end of file