Skip to content

Commit

Permalink
Fix single/double quote in strings (removed obsolete code)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauretto78 committed Sep 21, 2023
1 parent eafd676 commit 453adbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/Filters/Html/HtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ public function transform( $segment ) {
} elseif ( $state == static::STATE_HTML ) {
switch ( $char ) {
case '<':
// ignore '<' if inside a quote
if ( $in_quote_char ) {
break;
}
// is not possible to have angle brackets inside a tag, this case can not happen
// this code would ignore '>' if inside a quote, useless
// for more info see https://www.w3.org/TR/xml/#charsets
// if ( $in_quote_char ) {
// break;
// }

// if we found a second less than symbol the first one IS NOT a tag,
// treat the html_buffer as plain text and attach to the output
Expand All @@ -135,10 +137,12 @@ public function transform( $segment ) {
break;

case '>':
// ignore '>' if inside a quote
if ( $in_quote_char ) {
break;
}
// is not possible to have angle brackets inside a tag, this case can not happen
// this code would ignore '>' if inside a quote, useless
// for more info see https://www.w3.org/TR/xml/#charsets
// if ( $in_quote_char ) {
// break;
// }

if ( in_array( substr( $html_buffer, 0, 8 ), [ '<script ', '<style', '<script', '<style ' ] ) ) {
$html_buffer .= $char;
Expand Down
11 changes: 10 additions & 1 deletion tests/MateCatSubFilteringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Matecat\SubFiltering\MateCatFilter;
use Matecat\SubFiltering\Tests\Mocks\Features\AirbnbFeature;
use Matecat\SubFiltering\Tests\Mocks\FeatureSet;
use Matecat\SubFiltering\Utils\CatUtils;
use PHPUnit\Framework\TestCase;

class MateCatSubFilteringTest extends TestCase {
Expand Down Expand Up @@ -44,6 +43,16 @@ public function testSimpleString() {
$this->assertEquals( $segmentL1, $filter->fromLayer2ToLayer1( $tmpLayer2 ) );
}

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

$segment = "&lt;Value&gt; &lt;![CDATA[Visitez Singapour et détendez-vous sur l'île de Langkawi]]&gt; &lt;/Value&gt;";
$segmentL1 = $filter->fromLayer0ToLayer1( $segment );

$this->assertEquals( $segment, $filter->fromLayer1ToLayer0( $segmentL1 ) );
}

/**
* @throws Exception
*/
Expand Down

0 comments on commit 453adbb

Please sign in to comment.