Skip to content

Commit

Permalink
Fix nbsp handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mauretto78 committed Sep 7, 2023
1 parent 8cac260 commit f9c0112
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 43 deletions.
15 changes: 0 additions & 15 deletions src/Filters/RemoveNBSPPlaceholder.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Filters/RestoreNBSPPlaceholders.php

This file was deleted.

17 changes: 9 additions & 8 deletions src/Filters/SpacesToNBSPForView.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\Utils\CatUtils;
use Matecat\SubFiltering\Enum\ConstantEnum;

class SpacesToNBSPForView extends AbstractHandler {

Expand All @@ -23,15 +23,16 @@ public function transform( $segment ) {
$segment = str_ireplace(
[
'
', '
', ' ' /* NBSP in ascii value */,
'&#0A;', '&#0C;', '&#nbsp;'
'&#0A;', '&#0C;', ' ', ' ',
],
[
CatUtils::lfPlaceholder,
CatUtils::crPlaceholder,
CatUtils::nbspPlaceholder,
CatUtils::lfPlaceholder,
CatUtils::crPlaceholder,
CatUtils::nbspPlaceholder
ConstantEnum::lfPlaceholder,
ConstantEnum::crPlaceholder,
ConstantEnum::nbspPlaceholder,
ConstantEnum::lfPlaceholder,
ConstantEnum::crPlaceholder,
ConstantEnum::nbspPlaceholder,
ConstantEnum::nbspPlaceholder
], $segment );

return $segment;
Expand Down
4 changes: 0 additions & 4 deletions src/MateCatFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
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;
Expand Down Expand Up @@ -93,7 +91,6 @@ 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() );
Expand Down Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion tests/MateCatSubFilteringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ public function testHTMLFromLayer2() {

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
Expand Down

0 comments on commit f9c0112

Please sign in to comment.