Skip to content

Commit

Permalink
Merge pull request #41 from matecat/fix-apostrophe-in-simil-html
Browse files Browse the repository at this point in the history
Fix single/double quote in strings (removed obsolete code)
  • Loading branch information
mauretto78 committed Nov 28, 2023
2 parents 02ef243 + 453adbb commit bbeee5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Filters/Html/HtmlParser.php
Expand Up @@ -124,10 +124,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 @@ -136,10 +138,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
10 changes: 10 additions & 0 deletions tests/MateCatSubFilteringTest.php
Expand Up @@ -41,6 +41,16 @@ public function testSimpleString() {
$this->assertEquals( $segmentL1, $filter->fromLayer2ToLayer1( $segmentL2 ) );
}

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 bbeee5e

Please sign in to comment.