Skip to content

Commit

Permalink
Merge pull request #37 from matecat/nbsp
Browse files Browse the repository at this point in the history
Support for NBSP
  • Loading branch information
mauretto78 authored Sep 7, 2023
2 parents 903773a + c1a6853 commit 48de6ac
Show file tree
Hide file tree
Showing 28 changed files with 130 additions and 120 deletions.
4 changes: 2 additions & 2 deletions src/Commons/Constants.php → src/Enum/ConstantEnum.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Matecat\SubFiltering\Commons;
namespace Matecat\SubFiltering\Enum;


class Constants {
class ConstantEnum {

const LTPLACEHOLDER = "##LESSTHAN##";
const GTPLACEHOLDER = "##GREATERTHAN##";
Expand Down
10 changes: 5 additions & 5 deletions src/Filters/CtrlCharsPlaceHoldToAscii.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
namespace Matecat\SubFiltering\Filters;

use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;

class CtrlCharsPlaceHoldToAscii extends AbstractHandler {

public function transform( $segment ) {

//Replace br placeholders
$segment = str_replace( Constants::crlfPlaceholder, "\r\n", $segment );
$segment = str_replace( Constants::lfPlaceholder, "\n", $segment );
$segment = str_replace( Constants::crPlaceholder, "\r", $segment );
$segment = str_replace( Constants::tabPlaceholder, "\t", $segment );
$segment = str_replace( ConstantEnum::crlfPlaceholder, "\r\n", $segment );
$segment = str_replace( ConstantEnum::lfPlaceholder, "\n", $segment );
$segment = str_replace( ConstantEnum::crPlaceholder, "\r", $segment );
$segment = str_replace( ConstantEnum::tabPlaceholder, "\t", $segment );

return $segment;

Expand Down
4 changes: 2 additions & 2 deletions src/Filters/DollarCurlyBrackets.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Matecat\SubFiltering\Filters;

use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;
use Matecat\SubFiltering\Enum\CTypeEnum;

class DollarCurlyBrackets extends AbstractHandler {
Expand All @@ -14,7 +14,7 @@ public function transform( $segment ) {
preg_match_all( '/\$\{[^<>\s]+?\}/', $segment, $html, PREG_SET_ORDER );
foreach ( $html as $pos => $snail_variable ) {
//check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag
if ( !strstr( $snail_variable[ 0 ], Constants::GTPLACEHOLDER ) ) {
if ( !strstr( $snail_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) {
//replace subsequent elements excluding already encoded
$segment = preg_replace(
'/' . preg_quote( $snail_variable[ 0 ], '/' ) . '/',
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/DoubleSquareBrackets.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Matecat\SubFiltering\Filters;

use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;
use Matecat\SubFiltering\Enum\CTypeEnum;

class DoubleSquareBrackets extends AbstractHandler {
Expand All @@ -14,7 +14,7 @@ public function transform( $segment ) {
preg_match_all( '/\[\[[^<>\s]+?\]\]/', $segment, $html, PREG_SET_ORDER );
foreach ( $html as $pos => $snail_variable ) {
//check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag
if ( !strstr( $snail_variable[ 0 ], Constants::GTPLACEHOLDER ) ) {
if ( !strstr( $snail_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) {
//replace subsequent elements excluding already encoded
$segment = preg_replace(
'/' . preg_quote( $snail_variable[ 0 ], '/' ) . '/',
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/DoubleUnderscore.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Matecat\SubFiltering\Filters;

use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;
use Matecat\SubFiltering\Enum\CTypeEnum;

class DoubleUnderscore extends AbstractHandler {
Expand All @@ -14,7 +14,7 @@ public function transform( $segment ) {
preg_match_all( '/__[^<>\s]+?__/', $segment, $html, PREG_SET_ORDER );
foreach ( $html as $pos => $snail_variable ) {
//check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag
if ( !strstr( $snail_variable[ 0 ], Constants::GTPLACEHOLDER ) ) {
if ( !strstr( $snail_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) {
//replace subsequent elements excluding already encoded
$segment = preg_replace(
'/' . preg_quote( $snail_variable[ 0 ], '/' ) . '/',
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/EncodeToRawXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Matecat\SubFiltering\Filters;

use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;
use Matecat\SubFiltering\Utils\CatUtils;

class EncodeToRawXML extends AbstractHandler {
Expand All @@ -26,7 +26,7 @@ public function transform( $segment ) {
$segment = preg_replace_callback( '/([\xF0-\xF7]...)/s', [ CatUtils::class, 'htmlentitiesFromUnicode' ], $segment );

// now convert the real &nbsp;
$segment = str_replace( Constants::nbspPlaceholder, CatUtils::unicode2chr( 0Xa0 ), $segment );
$segment = str_replace( ConstantEnum::nbspPlaceholder, CatUtils::unicode2chr( 0Xa0 ), $segment );

// handling &#10;
if ( strpos( $segment, '##_ent_0D_##' ) !== false ) {
Expand Down
6 changes: 3 additions & 3 deletions src/Filters/FromLayer2ToRawXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Matecat\SubFiltering\Filters;

use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;
use Matecat\SubFiltering\Utils\CatUtils;

/**
Expand All @@ -29,7 +29,7 @@ public function transform( $segment ) {
$segment = $this->placeHoldBrokenHTML( $segment );

$double_encode = false;
if ( strpos( $segment, Constants::LTPLACEHOLDER ) !== false ) {
if ( strpos( $segment, ConstantEnum::LTPLACEHOLDER ) !== false ) {

$decXliff = new RestoreXliffTagsContent();
$test_segment = $decXliff->transform( $segment );
Expand Down Expand Up @@ -68,7 +68,7 @@ public function transform( $segment ) {
$segment = preg_replace_callback( '/([\xF0-\xF7]...)/s', [ CatUtils::class, 'htmlentitiesFromUnicode' ], $segment );

// now convert the real &nbsp;
$segment = str_replace( Constants::nbspPlaceholder, CatUtils::unicode2chr( 0Xa0 ), $segment );
$segment = str_replace( ConstantEnum::nbspPlaceholder, CatUtils::unicode2chr( 0Xa0 ), $segment );

// Filters BUG, segmentation on HTML, we should never get this at this level ( Should be fixed, anyway we try to cover )
$segment = $this->resetBrokenHTML( $segment );
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/HtmlToPh.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Matecat\SubFiltering\Filters;

use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;
use Matecat\SubFiltering\Enum\CTypeEnum;
use Matecat\SubFiltering\Filters\Html\CallbacksHandler;
use Matecat\SubFiltering\Filters\Html\HtmlParser;
Expand Down Expand Up @@ -117,7 +117,7 @@ protected function _isTagValid( $buffer ) {
//EX:
//original: &lt;a href=\"<x id="1">\"&gt;
// <a href=\"##LESSTHAN##eCBpZD0iMSIv##GREATERTHAN##\">
if ( strpos( $buffer, Constants::LTPLACEHOLDER ) !== false || strpos( $buffer, Constants::GTPLACEHOLDER ) !== false ) {
if ( strpos( $buffer, ConstantEnum::LTPLACEHOLDER ) !== false || strpos( $buffer, ConstantEnum::GTPLACEHOLDER ) !== false ) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Filters/Percentages.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Matecat\SubFiltering\Filters;

use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;
use Matecat\SubFiltering\Enum\CTypeEnum;

class Percentages extends AbstractHandler {
Expand All @@ -31,7 +31,7 @@ public function transform( $segment ) {
preg_match_all( '/%%[^<>\s%]+?%%/', $segment, $html, PREG_SET_ORDER ); // removed single percentage support '/(?<!{)%[^<>\s%]+?%/'
foreach ( $html as $pos => $percentage_variable ) {
//check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag
if ( !strstr( $percentage_variable[ 0 ], Constants::GTPLACEHOLDER ) ) {
if ( !strstr( $percentage_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) {
//replace subsequent elements excluding already encoded
$segment = preg_replace(
'/' . preg_quote( $percentage_variable[ 0 ], '/' ) . '/',
Expand Down
59 changes: 29 additions & 30 deletions src/Filters/PlaceHoldXliffTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

namespace Matecat\SubFiltering\Filters;


use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;

class PlaceHoldXliffTags extends AbstractHandler {

Expand All @@ -22,35 +21,35 @@ public function transform( $segment ) {
//remove not existent </x> tags
$segment = preg_replace( '|(</x>)|si', "", $segment );

//$segment=preg_replace('|<(g\s*.*?)>|si', Constants::LTPLACEHOLDER."$1".Constants::GTPLACEHOLDER,$segment);
$segment = preg_replace( '|<(g\s*id=["\']+.*?["\']+\s*[^<>]*?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(g\s*xid=["\']+.*?["\']+\s*[^<>]*?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );

$segment = preg_replace( '|<(/g)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );

$segment = preg_replace( '|<(x .*?/?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '#<(bx[ ]{0,}/?|bx .*?/?)>#si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '#<(ex[ ]{0,}/? |ex .*?/?)>#si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(bpt\s*.*?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/bpt)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(ept\s*.*?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/ept)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(ph .*?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/ph)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(ec .*?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/ec)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(sc .*?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/sc)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(pc .*?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/pc)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(it .*?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/it)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(mrk\s*.*?)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/mrk)>|si', Constants::LTPLACEHOLDER . "$1" . Constants::GTPLACEHOLDER, $segment );

return preg_replace_callback( '/' . Constants::LTPLACEHOLDER . '(.*?)' . Constants::GTPLACEHOLDER . '/u',
//$segment=preg_replace('|<(g\s*.*?)>|si', ConstantEnum::LTPLACEHOLDER."$1".ConstantEnum::GTPLACEHOLDER,$segment);
$segment = preg_replace( '|<(g\s*id=["\']+.*?["\']+\s*[^<>]*?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(g\s*xid=["\']+.*?["\']+\s*[^<>]*?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );

$segment = preg_replace( '|<(/g)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );

$segment = preg_replace( '|<(x .*?/?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '#<(bx[ ]{0,}/?|bx .*?/?)>#si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '#<(ex[ ]{0,}/? |ex .*?/?)>#si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(bpt\s*.*?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/bpt)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(ept\s*.*?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/ept)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(ph .*?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/ph)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(ec .*?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/ec)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(sc .*?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/sc)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(pc .*?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/pc)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(it .*?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/it)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(mrk\s*.*?)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );
$segment = preg_replace( '|<(/mrk)>|si', ConstantEnum::LTPLACEHOLDER . "$1" . ConstantEnum::GTPLACEHOLDER, $segment );

return preg_replace_callback( '/' . ConstantEnum::LTPLACEHOLDER . '(.*?)' . ConstantEnum::GTPLACEHOLDER . '/u',
function ( $matches ) {
return Constants::LTPLACEHOLDER . base64_encode( $matches[ 1 ] ) . Constants::GTPLACEHOLDER;
return ConstantEnum::LTPLACEHOLDER . base64_encode( $matches[ 1 ] ) . ConstantEnum::GTPLACEHOLDER;
}, $segment
); //base64 of the tag content to avoid unwanted manipulation
}
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/RestoreEquivTextPhToXliffOriginal.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;

class RestoreEquivTextPhToXliffOriginal extends AbstractHandler {

Expand All @@ -23,7 +23,7 @@ class RestoreEquivTextPhToXliffOriginal extends AbstractHandler {
public function transform( $segment ) {

//pipeline to convert back XLIFF PH to the original ones
preg_match_all( '/' . Constants::LTPLACEHOLDER . 'ph id\s*=\s*[\'"](?!mtc_).*?[\'"] ctype="x-twig" equiv-text\s*=\s*[\'"]base64:([^"\']+?)[\'"]\s*\/' . Constants::GTPLACEHOLDER . '/', $segment, $html, PREG_SET_ORDER ); // Ungreedy
preg_match_all( '/' . ConstantEnum::LTPLACEHOLDER . 'ph id\s*=\s*[\'"](?!mtc_).*?[\'"] ctype="x-twig" equiv-text\s*=\s*[\'"]base64:([^"\']+?)[\'"]\s*\/' . ConstantEnum::GTPLACEHOLDER . '/', $segment, $html, PREG_SET_ORDER ); // Ungreedy
foreach ( $html as $tag_attribute ) {
$segment = str_replace( "base64:" . $tag_attribute[ 1 ], base64_decode( $tag_attribute[ 1 ] ), $segment );
}
Expand Down
6 changes: 3 additions & 3 deletions src/Filters/RestorePlaceHoldersToXLIFFLtGt.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@


use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;

class RestorePlaceHoldersToXLIFFLtGt extends AbstractHandler {

public function transform( $segment ) {
$segment = str_replace( Constants::LTPLACEHOLDER, "<", $segment );
$segment = str_replace( Constants::GTPLACEHOLDER, ">", $segment );
$segment = str_replace( ConstantEnum::LTPLACEHOLDER, "<", $segment );
$segment = str_replace( ConstantEnum::GTPLACEHOLDER, ">", $segment );

return $segment;

Expand Down
4 changes: 2 additions & 2 deletions src/Filters/RestoreSubFilteredPhToHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
namespace Matecat\SubFiltering\Filters;

use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;

class RestoreSubFilteredPhToHtml extends AbstractHandler {

const matchPhRegexp = '|' . Constants::LTPLACEHOLDER . 'ph id\s*=\s*["\']mtc_[0-9]+["\'] equiv-text\s*=\s*["\']base64:([^"\']+)["\']\s*/' . Constants::GTPLACEHOLDER . '|siU';
const matchPhRegexp = '|' . ConstantEnum::LTPLACEHOLDER . 'ph id\s*=\s*["\']mtc_[0-9]+["\'] equiv-text\s*=\s*["\']base64:([^"\']+)["\']\s*/' . ConstantEnum::GTPLACEHOLDER . '|siU';

/**
* @param $segment
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/RestoreTabsPlaceholders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Matecat\SubFiltering\Filters;

use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;

class RestoreTabsPlaceholders extends AbstractHandler {

Expand All @@ -17,7 +17,7 @@ public function transform( $segment ) {
// | Esempio &#09;test | Test example |
// +-------------------+--------------------+
//
return str_replace( [ "&#09;", " " ], Constants::tabPlaceholder, $segment );
return str_replace( [ "&#09;", " " ], ConstantEnum::tabPlaceholder, $segment );
}

}
6 changes: 3 additions & 3 deletions src/Filters/RestoreXliffTagsContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@


use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Commons\Constants;
use Matecat\SubFiltering\Enum\ConstantEnum;

class RestoreXliffTagsContent extends AbstractHandler {

public function transform( $segment ) {

$segment = preg_replace_callback( '/' . Constants::LTPLACEHOLDER . '(.*?)' . Constants::GTPLACEHOLDER . '/u',
$segment = preg_replace_callback( '/' . ConstantEnum::LTPLACEHOLDER . '(.*?)' . ConstantEnum::GTPLACEHOLDER . '/u',
function ( $matches ) {
$_match = base64_decode( $matches[ 1 ] );

return Constants::LTPLACEHOLDER . $_match . Constants::GTPLACEHOLDER;
return ConstantEnum::LTPLACEHOLDER . $_match . ConstantEnum::GTPLACEHOLDER;
},
$segment
); //base64 decode of the tag content to avoid unwanted manipulation
Expand Down
Loading

0 comments on commit 48de6ac

Please sign in to comment.