diff --git a/src/Utils/DataRefReplacer.php b/src/Utils/DataRefReplacer.php index 237e69a..4532090 100644 --- a/src/Utils/DataRefReplacer.php +++ b/src/Utils/DataRefReplacer.php @@ -371,10 +371,15 @@ private function recursiveRestoreOriginalTags( $node, $string ) { } else { $nodeAttributesMap = Map::instance( $node->attributes ); - $cType = $nodeAttributesMap->get( 'ctype' ); + + if ( !$nodeAttributesMap->get( 'x-orig' ) ) { + return $string; + } + + $cType = $nodeAttributesMap->get( 'ctype' ); if ( CTypeEnum::isLayer2Constant( $cType ) ) { - return preg_replace( '/' . preg_quote( $node->node, '/' ) . '/', base64_decode( $node->attributes[ 'x-orig' ] ), $string, 1 ); + return preg_replace( '/' . preg_quote( $node->node, '/' ) . '/', base64_decode( $nodeAttributesMap->get( 'x-orig' ) ), $string, 1 ); } } diff --git a/tests/MateCatSubFilteringTest.php b/tests/MateCatSubFilteringTest.php index 889f59b..602e0ac 100644 --- a/tests/MateCatSubFilteringTest.php +++ b/tests/MateCatSubFilteringTest.php @@ -1357,7 +1357,7 @@ public function testRubyOnRails() { $segment = 'For the %{first_ruby_variable} site %{{second_bnb_variable}}, is ok.'; $forUI = 'For the site , is ok.'; - $filter = $this->getFilterInstance(); + $filter = $this->getFilterInstance(); $segmentL1 = $filter->fromLayer0ToLayer1( $segment ); $this->assertEquals( $segment, $filter->fromLayer1ToLayer0( $segmentL1 ) ); @@ -1370,4 +1370,35 @@ public function testRubyOnRails() { } + /** + * @test + * @throws Exception + */ + public function nested_pc_tags_real_case() { + + $refMap = [ + 'source1' => '<w:hyperlink r:id="rId25"></w:hyperlink>', + 'source2' => '<w:r><w:rPr><w:color w:val="1A1A1A"></w:color></w:rPr><w:t></w:t></w:r>', + ]; + + $filter = $this->getFilterInstance( $refMap ); + + $segment = 'Crea una carpeta separada en tu Cuenta de ahorros Square para impuestos y automáticamente contribuye un porcentaje de cada venta de Square.'; + $sentFromUI = 'Crea una carpeta separada en tu Cuenta de ahorros Square para impuestos y automáticamente contribuye un porcentaje de cada venta de Square.'; + + $segmentL1 = $filter->fromLayer0ToLayer1( $segment ); + $this->assertEquals( $segment, $filter->fromLayer1ToLayer0( $segmentL1 ) ); + + // layer 2 + $segmentL2 = $filter->fromLayer0ToLayer2( $segment ); + $this->assertEquals( $segmentL2, $filter->fromLayer1ToLayer2( $segmentL1 ) ); + $this->assertEquals( $sentFromUI, $segmentL2 ); + + $this->assertEquals( $segment, $filter->fromLayer2ToLayer0( $segmentL2 ) ); + $this->assertEquals( $segment, $filter->fromLayer2ToLayer0( $sentFromUI ) ); + + $this->assertEquals( $segmentL1, $filter->fromLayer2ToLayer1( $segmentL2 ) ); + + } + }