From 8cac2601f0c0b439a667a0ca0d94e91447f6e87b Mon Sep 17 00:00:00 2001 From: Mauro Cassani Date: Wed, 6 Sep 2023 18:26:25 +0200 Subject: [PATCH 1/3] Support for NBSP --- .../Constants.php => Enum/ConstantEnum.php} | 4 +- src/Filters/CtrlCharsPlaceHoldToAscii.php | 10 ++-- src/Filters/DollarCurlyBrackets.php | 4 +- src/Filters/DoubleSquareBrackets.php | 4 +- src/Filters/DoubleUnderscore.php | 4 +- src/Filters/EncodeToRawXML.php | 4 +- src/Filters/FromLayer2ToRawXML.php | 6 +- src/Filters/HtmlToPh.php | 4 +- src/Filters/Percentages.php | 4 +- src/Filters/PlaceHoldXliffTags.php | 59 +++++++++---------- src/Filters/RemoveNBSPPlaceholder.php | 15 +++++ .../RestoreEquivTextPhToXliffOriginal.php | 4 +- src/Filters/RestoreNBSPPlaceholders.php | 15 +++++ .../RestorePlaceHoldersToXLIFFLtGt.php | 6 +- src/Filters/RestoreSubFilteredPhToHtml.php | 4 +- src/Filters/RestoreTabsPlaceholders.php | 4 +- src/Filters/RestoreXliffTagsContent.php | 6 +- src/Filters/RestoreXliffTagsForView.php | 11 ++-- src/Filters/RestoreXliffTagsInXliff.php | 6 +- src/Filters/RubyOnRailsI18n.php | 4 +- src/Filters/SingleCurlyBracketsToPh.php | 4 +- src/Filters/Snails.php | 4 +- src/Filters/SplitPlaceholder.php | 4 +- src/Filters/SubFilteredPhToHtml.php | 44 +++++++------- src/Filters/TwigToPh.php | 4 +- src/MateCatFilter.php | 6 +- src/MyMemoryFilter.php | 1 - tests/MateCatSubFilteringTest.php | 17 ++++++ 28 files changed, 154 insertions(+), 108 deletions(-) rename src/{Commons/Constants.php => Enum/ConstantEnum.php} (90%) create mode 100644 src/Filters/RemoveNBSPPlaceholder.php create mode 100644 src/Filters/RestoreNBSPPlaceholders.php diff --git a/src/Commons/Constants.php b/src/Enum/ConstantEnum.php similarity index 90% rename from src/Commons/Constants.php rename to src/Enum/ConstantEnum.php index 7c16c26..c1e5bab 100644 --- a/src/Commons/Constants.php +++ b/src/Enum/ConstantEnum.php @@ -1,9 +1,9 @@ \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 ], '/' ) . '/', diff --git a/src/Filters/DoubleSquareBrackets.php b/src/Filters/DoubleSquareBrackets.php index c5da671..e47d125 100644 --- a/src/Filters/DoubleSquareBrackets.php +++ b/src/Filters/DoubleSquareBrackets.php @@ -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 { @@ -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 ], '/' ) . '/', diff --git a/src/Filters/DoubleUnderscore.php b/src/Filters/DoubleUnderscore.php index f370cb2..2c9d081 100644 --- a/src/Filters/DoubleUnderscore.php +++ b/src/Filters/DoubleUnderscore.php @@ -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 { @@ -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 ], '/' ) . '/', diff --git a/src/Filters/EncodeToRawXML.php b/src/Filters/EncodeToRawXML.php index 4c26eae..73a6d4f 100644 --- a/src/Filters/EncodeToRawXML.php +++ b/src/Filters/EncodeToRawXML.php @@ -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 { @@ -26,7 +26,7 @@ public function transform( $segment ) { $segment = preg_replace_callback( '/([\xF0-\xF7]...)/s', [ CatUtils::class, 'htmlentitiesFromUnicode' ], $segment ); // now convert the real   - $segment = str_replace( Constants::nbspPlaceholder, CatUtils::unicode2chr( 0Xa0 ), $segment ); + $segment = str_replace( ConstantEnum::nbspPlaceholder, CatUtils::unicode2chr( 0Xa0 ), $segment ); // handling if ( strpos( $segment, '##_ent_0D_##' ) !== false ) { diff --git a/src/Filters/FromLayer2ToRawXML.php b/src/Filters/FromLayer2ToRawXML.php index 657648b..6f58510 100644 --- a/src/Filters/FromLayer2ToRawXML.php +++ b/src/Filters/FromLayer2ToRawXML.php @@ -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; /** @@ -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 ); @@ -68,7 +68,7 @@ public function transform( $segment ) { $segment = preg_replace_callback( '/([\xF0-\xF7]...)/s', [ CatUtils::class, 'htmlentitiesFromUnicode' ], $segment ); // now convert the real   - $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 ); diff --git a/src/Filters/HtmlToPh.php b/src/Filters/HtmlToPh.php index d83ac4e..309f235 100644 --- a/src/Filters/HtmlToPh.php +++ b/src/Filters/HtmlToPh.php @@ -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; @@ -117,7 +117,7 @@ protected function _isTagValid( $buffer ) { //EX: //original: <a href=\"\"> // - if ( strpos( $buffer, Constants::LTPLACEHOLDER ) !== false || strpos( $buffer, Constants::GTPLACEHOLDER ) !== false ) { + if ( strpos( $buffer, ConstantEnum::LTPLACEHOLDER ) !== false || strpos( $buffer, ConstantEnum::GTPLACEHOLDER ) !== false ) { return false; } diff --git a/src/Filters/Percentages.php b/src/Filters/Percentages.php index 981abba..313f68e 100644 --- a/src/Filters/Percentages.php +++ b/src/Filters/Percentages.php @@ -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 { @@ -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 ], '/' ) . '/', diff --git a/src/Filters/PlaceHoldXliffTags.php b/src/Filters/PlaceHoldXliffTags.php index 608626c..12334d5 100644 --- a/src/Filters/PlaceHoldXliffTags.php +++ b/src/Filters/PlaceHoldXliffTags.php @@ -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 { @@ -22,35 +21,35 @@ public function transform( $segment ) { //remove not existent tags $segment = preg_replace( '|()|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 } diff --git a/src/Filters/RemoveNBSPPlaceholder.php b/src/Filters/RemoveNBSPPlaceholder.php new file mode 100644 index 0000000..889fedc --- /dev/null +++ b/src/Filters/RemoveNBSPPlaceholder.php @@ -0,0 +1,15 @@ +", $segment ); + $segment = str_replace( ConstantEnum::LTPLACEHOLDER, "<", $segment ); + $segment = str_replace( ConstantEnum::GTPLACEHOLDER, ">", $segment ); return $segment; diff --git a/src/Filters/RestoreSubFilteredPhToHtml.php b/src/Filters/RestoreSubFilteredPhToHtml.php index fad7233..11239c8 100644 --- a/src/Filters/RestoreSubFilteredPhToHtml.php +++ b/src/Filters/RestoreSubFilteredPhToHtml.php @@ -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 diff --git a/src/Filters/RestoreTabsPlaceholders.php b/src/Filters/RestoreTabsPlaceholders.php index 929d544..e9ba24b 100644 --- a/src/Filters/RestoreTabsPlaceholders.php +++ b/src/Filters/RestoreTabsPlaceholders.php @@ -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 { @@ -17,7 +17,7 @@ public function transform( $segment ) { // | Esempio test | Test example | // +-------------------+--------------------+ // - return str_replace( [ " ", " " ], Constants::tabPlaceholder, $segment ); + return str_replace( [ " ", " " ], ConstantEnum::tabPlaceholder, $segment ); } } \ No newline at end of file diff --git a/src/Filters/RestoreXliffTagsContent.php b/src/Filters/RestoreXliffTagsContent.php index 6c1abe1..38e1c79 100644 --- a/src/Filters/RestoreXliffTagsContent.php +++ b/src/Filters/RestoreXliffTagsContent.php @@ -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 diff --git a/src/Filters/RestoreXliffTagsForView.php b/src/Filters/RestoreXliffTagsForView.php index 6d19b2f..1747c0a 100644 --- a/src/Filters/RestoreXliffTagsForView.php +++ b/src/Filters/RestoreXliffTagsForView.php @@ -9,19 +9,18 @@ namespace Matecat\SubFiltering\Filters; - use Matecat\SubFiltering\Commons\AbstractHandler; -use Matecat\SubFiltering\Commons\Constants; +use Matecat\SubFiltering\Enum\ConstantEnum; class RestoreXliffTagsForView 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 @@ -32,8 +31,8 @@ function ( $matches ) { $segment = str_replace( $tag_attribute[ 0 ], 'equiv-text="base64:' . base64_encode( $tag_attribute[ 2 ] ) . "\"", $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; diff --git a/src/Filters/RestoreXliffTagsInXliff.php b/src/Filters/RestoreXliffTagsInXliff.php index 2ebdda6..2248e32 100644 --- a/src/Filters/RestoreXliffTagsInXliff.php +++ b/src/Filters/RestoreXliffTagsInXliff.php @@ -3,7 +3,7 @@ namespace Matecat\SubFiltering\Filters; use Matecat\SubFiltering\Commons\AbstractHandler; -use Matecat\SubFiltering\Commons\Constants; +use Matecat\SubFiltering\Enum\ConstantEnum; class RestoreXliffTagsInXliff extends AbstractHandler { @@ -11,8 +11,8 @@ class RestoreXliffTagsInXliff extends AbstractHandler { * @inheritDoc */ public function transform( $segment ) { - $segment = str_replace( Constants::xliffInXliffStartPlaceHolder, "<", $segment ); - $segment = str_replace( Constants::xliffInXliffEndPlaceHolder, ">", $segment ); + $segment = str_replace( ConstantEnum::xliffInXliffStartPlaceHolder, "<", $segment ); + $segment = str_replace( ConstantEnum::xliffInXliffEndPlaceHolder, ">", $segment ); return $segment; } diff --git a/src/Filters/RubyOnRailsI18n.php b/src/Filters/RubyOnRailsI18n.php index 3912fe7..2d181d5 100644 --- a/src/Filters/RubyOnRailsI18n.php +++ b/src/Filters/RubyOnRailsI18n.php @@ -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 RubyOnRailsI18n extends AbstractHandler { @@ -31,7 +31,7 @@ public function transform( $segment ) { preg_match_all( '/%{[^<>\s%]+?}/', $segment, $html, PREG_SET_ORDER ); 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 ], '/' ) . '/', diff --git a/src/Filters/SingleCurlyBracketsToPh.php b/src/Filters/SingleCurlyBracketsToPh.php index a4dcc70..adf2790 100644 --- a/src/Filters/SingleCurlyBracketsToPh.php +++ b/src/Filters/SingleCurlyBracketsToPh.php @@ -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 SingleCurlyBracketsToPh extends AbstractHandler { @@ -36,7 +36,7 @@ public function transform( $segment ) { 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 ) ) { + if ( !strstr( $twig_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) { //replace subsequent elements excluding already encoded $segment = preg_replace( '/' . preg_quote( $twig_variable[ 0 ], '/' ) . '/', diff --git a/src/Filters/Snails.php b/src/Filters/Snails.php index 240d29f..02b1f52 100644 --- a/src/Filters/Snails.php +++ b/src/Filters/Snails.php @@ -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 Snails extends AbstractHandler { @@ -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 ], '/' ) . '/', diff --git a/src/Filters/SplitPlaceholder.php b/src/Filters/SplitPlaceholder.php index 7f56c05..2a2325e 100644 --- a/src/Filters/SplitPlaceholder.php +++ b/src/Filters/SplitPlaceholder.php @@ -9,11 +9,11 @@ namespace Matecat\SubFiltering\Filters; use Matecat\SubFiltering\Commons\AbstractHandler; -use Matecat\SubFiltering\Commons\Constants; +use Matecat\SubFiltering\Enum\ConstantEnum; class SplitPlaceholder extends AbstractHandler { public function transform( $segment ) { - $segment = str_replace( Constants::splitPlaceHolder, "", $segment ); + $segment = str_replace( ConstantEnum::splitPlaceHolder, "", $segment ); return $segment; } diff --git a/src/Filters/SubFilteredPhToHtml.php b/src/Filters/SubFilteredPhToHtml.php index cc4b84d..d419173 100644 --- a/src/Filters/SubFilteredPhToHtml.php +++ b/src/Filters/SubFilteredPhToHtml.php @@ -3,7 +3,7 @@ namespace Matecat\SubFiltering\Filters; use Matecat\SubFiltering\Commons\AbstractHandler; -use Matecat\SubFiltering\Commons\Constants; +use Matecat\SubFiltering\Enum\ConstantEnum; class SubFilteredPhToHtml extends AbstractHandler { @@ -41,29 +41,29 @@ public function transform( $segment ) { */ private function placeholdXliffTagsInXliff( $value ) { $value = preg_replace( '|(</x>)|si', "", $value ); - $value = preg_replace( '#<(g\s*id=["\']+.*?["\']+\s*(?!<|>)*?)>#si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '#<(g\s*id=["\']+.*?["\']+\s*(?!<|>)*?)>#si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(/g)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(/g)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(x .*?/?)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '#<(bx[ ]{0,}/?|bx .*?/?)>#si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '#<(ex[ ]{0,}/?|ex .*?/?)>#si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(bpt\s*.*?)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(/bpt)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(ept\s*.*?)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(/ept)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(ph .*?)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(/ph)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(ec .*?)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(/ec)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(sc .*?)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(/sc)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(pc .*?)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(/pc)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(it .*?)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(/it)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(mrk\s*.*?)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); - $value = preg_replace( '|<(/mrk)>|si', Constants::xliffInXliffStartPlaceHolder . "$1" . Constants::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(x .*?/?)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '#<(bx[ ]{0,}/?|bx .*?/?)>#si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '#<(ex[ ]{0,}/?|ex .*?/?)>#si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(bpt\s*.*?)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(/bpt)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(ept\s*.*?)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(/ept)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(ph .*?)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(/ph)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(ec .*?)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(/ec)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(sc .*?)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(/sc)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(pc .*?)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(/pc)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(it .*?)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(/it)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(mrk\s*.*?)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); + $value = preg_replace( '|<(/mrk)>|si', ConstantEnum::xliffInXliffStartPlaceHolder . "$1" . ConstantEnum::xliffInXliffEndPlaceHolder, $value ); return $value; } diff --git a/src/Filters/TwigToPh.php b/src/Filters/TwigToPh.php index 617a6a4..eb72aeb 100644 --- a/src/Filters/TwigToPh.php +++ b/src/Filters/TwigToPh.php @@ -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 TwigToPh extends AbstractHandler { @@ -36,7 +36,7 @@ public function transform( $segment ) { 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 ) ) { + if ( !strstr( $twig_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) { //replace subsequent elements excluding already encoded $segment = preg_replace( '/' . preg_quote( $twig_variable[ 0 ], '/' ) . '/', diff --git a/src/MateCatFilter.php b/src/MateCatFilter.php index c938160..c04457e 100644 --- a/src/MateCatFilter.php +++ b/src/MateCatFilter.php @@ -8,7 +8,6 @@ use Matecat\SubFiltering\Filters\DataRefRestore; use Matecat\SubFiltering\Filters\DollarCurlyBrackets; use Matecat\SubFiltering\Filters\DoubleSquareBrackets; -use Matecat\SubFiltering\Filters\DoubleUnderscore; use Matecat\SubFiltering\Filters\EncodeToRawXML; use Matecat\SubFiltering\Filters\FromLayer2ToRawXML; use Matecat\SubFiltering\Filters\FromViewNBSPToSpaces; @@ -20,12 +19,13 @@ use Matecat\SubFiltering\Filters\MateCatCustomPHToStandardPH; use Matecat\SubFiltering\Filters\Percentages; use Matecat\SubFiltering\Filters\PercentNumberSnail; -use Matecat\SubFiltering\Filters\PercentSnail; use Matecat\SubFiltering\Filters\PlaceBreakingSpacesInXliff; use Matecat\SubFiltering\Filters\PlaceHoldXliffTags; use Matecat\SubFiltering\Filters\RemoveCTypeFromPhTags; use Matecat\SubFiltering\Filters\RemoveDangerousChars; +use Matecat\SubFiltering\Filters\RemoveNBSPPlaceholder; use Matecat\SubFiltering\Filters\RestoreEquivTextPhToXliffOriginal; +use Matecat\SubFiltering\Filters\RestoreNBSPPlaceholders; use Matecat\SubFiltering\Filters\RestorePlaceHoldersToXLIFFLtGt; use Matecat\SubFiltering\Filters\RestoreTabsPlaceholders; use Matecat\SubFiltering\Filters\RestoreXliffTagsContent; @@ -93,6 +93,7 @@ public function fromLayer1ToLayer2( $segment ) { $channel->addLast( new SpacesToNBSPForView() ); $channel->addLast( new RestoreXliffTagsForView() ); $channel->addLast( new RestoreTabsPlaceholders() ); + $channel->addLast( new RestoreNBSPPlaceholders() ); $channel->addLast( new HtmlPlainTextDecoder() ); $channel->addLast( new LtGtDoubleEncode() ); $channel->addLast( new LtGtEncode() ); @@ -190,6 +191,7 @@ public function fromLayer0ToLayer1( $segment ) { public function fromLayer1ToLayer0( $segment ) { $channel = new Pipeline( $this->source, $this->target, $this->dataRefMap ); $channel->addLast( new DataRefRestore() ); + $channel->addLast( new RemoveNBSPPlaceholder() ); $channel->addLast( new FromViewNBSPToSpaces() ); $channel->addLast( new CtrlCharsPlaceHoldToAscii() ); $channel->addLast( new MateCatCustomPHToStandardPH() ); diff --git a/src/MyMemoryFilter.php b/src/MyMemoryFilter.php index 8103f0a..6f42aa6 100644 --- a/src/MyMemoryFilter.php +++ b/src/MyMemoryFilter.php @@ -8,7 +8,6 @@ use Matecat\SubFiltering\Filters\DollarCurlyBrackets; use Matecat\SubFiltering\Filters\DoubleSnail; use Matecat\SubFiltering\Filters\DoubleSquareBrackets; -use Matecat\SubFiltering\Filters\DoubleUnderscore; use Matecat\SubFiltering\Filters\EncodeToRawXML; use Matecat\SubFiltering\Filters\FromViewNBSPToSpaces; use Matecat\SubFiltering\Filters\HtmlPlainTextDecoder; diff --git a/tests/MateCatSubFilteringTest.php b/tests/MateCatSubFilteringTest.php index 6cc5b81..22b60c6 100644 --- a/tests/MateCatSubFilteringTest.php +++ b/tests/MateCatSubFilteringTest.php @@ -4,6 +4,7 @@ use Exception; use Matecat\SubFiltering\Commons\Pipeline; +use Matecat\SubFiltering\Enum\ConstantEnum; use Matecat\SubFiltering\Enum\CTypeEnum; use Matecat\SubFiltering\Filters\LtGtDecode; use Matecat\SubFiltering\Filters\SprintfToPH; @@ -256,6 +257,22 @@ public function testHTMLFromLayer2() { } + /** + ************************** + * NBSP + ************************** + */ + + public function testNbsp() { + $filter = $this->getFilterInstance(); + $expected_segment = '   Test'; + $string_from_UI = ConstantEnum::nbspPlaceholder.ConstantEnum::nbspPlaceholder.ConstantEnum::nbspPlaceholder.'Test'; + + $this->assertEquals( $expected_segment, $filter->fromLayer2ToLayer0( $string_from_UI ) ); + $this->assertEquals( $string_from_UI, $filter->fromLayer0ToLayer2( $expected_segment ) ); + } + + /** ************************** * Sprintf From f9c0112903164137c63f4a25facd70260ba592b2 Mon Sep 17 00:00:00 2001 From: Mauro Cassani Date: Thu, 7 Sep 2023 13:40:34 +0200 Subject: [PATCH 2/3] Fix nbsp handling --- src/Filters/RemoveNBSPPlaceholder.php | 15 --------------- src/Filters/RestoreNBSPPlaceholders.php | 15 --------------- src/Filters/SpacesToNBSPForView.php | 17 +++++++++-------- src/MateCatFilter.php | 4 ---- tests/MateCatSubFilteringTest.php | 2 +- 5 files changed, 10 insertions(+), 43 deletions(-) delete mode 100644 src/Filters/RemoveNBSPPlaceholder.php delete mode 100644 src/Filters/RestoreNBSPPlaceholders.php diff --git a/src/Filters/RemoveNBSPPlaceholder.php b/src/Filters/RemoveNBSPPlaceholder.php deleted file mode 100644 index 889fedc..0000000 --- a/src/Filters/RemoveNBSPPlaceholder.php +++ /dev/null @@ -1,15 +0,0 @@ -addLast( new SpacesToNBSPForView() ); $channel->addLast( new RestoreXliffTagsForView() ); $channel->addLast( new RestoreTabsPlaceholders() ); - $channel->addLast( new RestoreNBSPPlaceholders() ); $channel->addLast( new HtmlPlainTextDecoder() ); $channel->addLast( new LtGtDoubleEncode() ); $channel->addLast( new LtGtEncode() ); @@ -191,7 +188,6 @@ public function fromLayer0ToLayer1( $segment ) { public function fromLayer1ToLayer0( $segment ) { $channel = new Pipeline( $this->source, $this->target, $this->dataRefMap ); $channel->addLast( new DataRefRestore() ); - $channel->addLast( new RemoveNBSPPlaceholder() ); $channel->addLast( new FromViewNBSPToSpaces() ); $channel->addLast( new CtrlCharsPlaceHoldToAscii() ); $channel->addLast( new MateCatCustomPHToStandardPH() ); diff --git a/tests/MateCatSubFilteringTest.php b/tests/MateCatSubFilteringTest.php index 22b60c6..87de3ec 100644 --- a/tests/MateCatSubFilteringTest.php +++ b/tests/MateCatSubFilteringTest.php @@ -265,6 +265,7 @@ public function testHTMLFromLayer2() { public function testNbsp() { $filter = $this->getFilterInstance(); + $expected_segment = '   Test'; $string_from_UI = ConstantEnum::nbspPlaceholder.ConstantEnum::nbspPlaceholder.ConstantEnum::nbspPlaceholder.'Test'; @@ -272,7 +273,6 @@ public function testNbsp() { $this->assertEquals( $string_from_UI, $filter->fromLayer0ToLayer2( $expected_segment ) ); } - /** ************************** * Sprintf From c1a6853fbf3617da3420584c7944b219b80d79fb Mon Sep 17 00:00:00 2001 From: Mauro Cassani Date: Thu, 7 Sep 2023 14:46:58 +0200 Subject: [PATCH 3/3] Removed unused constants --- src/Utils/CatUtils.php | 3 --- tests/MateCatSubFilteringTest.php | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Utils/CatUtils.php b/src/Utils/CatUtils.php index 7c3db50..bd5c6bc 100644 --- a/src/Utils/CatUtils.php +++ b/src/Utils/CatUtils.php @@ -3,9 +3,6 @@ namespace Matecat\SubFiltering\Utils; class CatUtils { - const lfPlaceholder = '##$_0A$##'; - const crPlaceholder = '##$_0D$##'; - const nbspPlaceholder = '##$_A0$##'; /** * Get the char code from a multi byte char diff --git a/tests/MateCatSubFilteringTest.php b/tests/MateCatSubFilteringTest.php index 87de3ec..cfa265f 100644 --- a/tests/MateCatSubFilteringTest.php +++ b/tests/MateCatSubFilteringTest.php @@ -226,7 +226,7 @@ public function test_3_HandlingNBSP() { $filter = $this->getFilterInstance(); $segment = $expectedL1 = '5 tips for creating a great   guide'; - $segment_to_UI = $string_from_UI = '5 tips for creating a great ' . CatUtils::nbspPlaceholder . ' guide'; + $segment_to_UI = $string_from_UI = '5 tips for creating a great ' . ConstantEnum::nbspPlaceholder . ' guide'; $segmentL1 = $filter->fromLayer0ToLayer1( $segment ); $segmentL2 = $filter->fromLayer0ToLayer2( $segment );