Skip to content

Commit

Permalink
Fix handling for <ph> with no dataRef attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Cassani committed Aug 20, 2021
1 parent a19541e commit f34c48d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Filters/DataRefReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,21 @@ private function isAPhTagWithNoDataRefCorrespondence($phTag)
{
$parsed = HtmlParser::parse($phTag);

return (
isset($parsed[0]) and
isset($parsed[0]->attributes['dataRef']) and
!isset($parsed[0]->attributes['equiv-text']) and
!array_key_exists($parsed[0]->attributes['dataRef'], $this->dataRefMap
));
if(!isset($parsed[0])){
return false;
}

// if has equiv-text don't touch
if(isset($parsed[0]->attributes['equiv-text'])){
return false;
}

// if has dataRef attribute check if there is correspondence on dataRef map
if(isset($parsed[0]->attributes['dataRef'])){
return !array_key_exists($parsed[0]->attributes['dataRef'], $this->dataRefMap);
}

return true;
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/MateCatSubFilteringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,4 +659,24 @@ public function testHtmlStringsWithDataTypeAttribute()

$this->assertEquals($back_to_db_segment, $db_segment);
}

public function testPhTagsWithoutDataRef()
{
$Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] );

//dataRef="source1"
$db_segment = '<ph id="1j" type="other" subType="m:j"/>';
$expected_l1_segment = '<ph id="1j" type="other" subType="m:j"/>';
$expected_l2_segment = '&lt;ph id="mtc_ph_u_1" equiv-text="base64:Jmx0O3BoIGlkPSIxaiIgdHlwZT0ib3RoZXIiIHN1YlR5cGU9Im06aiIvJmd0Ow=="/&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_segment = $Filter->fromLayer1ToLayer0($l1_segment);

$this->assertEquals($back_to_db_segment, $db_segment);
}
}

0 comments on commit f34c48d

Please sign in to comment.