Skip to content

Commit

Permalink
NBSP double encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mauretto78 committed Sep 8, 2023
1 parent 48de6ac commit 3bd5051
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Filters/NBSPDoubleEncode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php


namespace Matecat\SubFiltering\Filters;


use Matecat\SubFiltering\Commons\AbstractHandler;

class NBSPDoubleEncode extends AbstractHandler {

public function transform( $segment ) {
$segment = str_replace( "&nbsp;", "&amp;nbsp;", $segment );

return $segment;
}

}
2 changes: 2 additions & 0 deletions src/MateCatFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Matecat\SubFiltering\Filters\LtGtDoubleEncode;
use Matecat\SubFiltering\Filters\LtGtEncode;
use Matecat\SubFiltering\Filters\MateCatCustomPHToStandardPH;
use Matecat\SubFiltering\Filters\NBSPDoubleEncode;
use Matecat\SubFiltering\Filters\Percentages;
use Matecat\SubFiltering\Filters\PercentNumberSnail;
use Matecat\SubFiltering\Filters\PlaceBreakingSpacesInXliff;
Expand Down Expand Up @@ -93,6 +94,7 @@ public function fromLayer1ToLayer2( $segment ) {
$channel->addLast( new RestoreTabsPlaceholders() );
$channel->addLast( new HtmlPlainTextDecoder() );
$channel->addLast( new LtGtDoubleEncode() );
$channel->addLast( new NBSPDoubleEncode() );
$channel->addLast( new LtGtEncode() );
$channel->addLast( new DataRefReplace() );

Expand Down
10 changes: 10 additions & 0 deletions tests/MateCatSubFilteringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ public function testNbsp() {
$this->assertEquals( $string_from_UI, $filter->fromLayer0ToLayer2( $expected_segment ) );
}

public function testNbspAsString() {
$filter = $this->getFilterInstance();

$expected_segment = '&amp;nbsp; Text';
$string_from_UI = '&amp;nbsp; Text';

$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 3bd5051

Please sign in to comment.