Skip to content

Commit

Permalink
Merge branch 'release/v1.03.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mekras committed May 13, 2015
2 parents 879825f + db41526 commit cd59137
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.03
1.03.1
22 changes: 21 additions & 1 deletion src/Source/Filter/HtmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function filter($string)
{
$result = '';

$string = $this->filterEntities($string);

// Current/last tag name
$tagName = null;
// Current/last attribute name
Expand Down Expand Up @@ -116,7 +118,7 @@ public function filter($string)
case 'tag_attrs':
$context = 'attr_name';
$attrName = null;
// no break needed
// no break needed
case 'attr_name':
$attrName .= $ch;
$ch = ' ';
Expand All @@ -132,4 +134,22 @@ public function filter($string)

return $result;
}

/**
* Replace HTML entities
*
* @param string $string
*
* @return string
*/
private function filterEntities($string)
{
return preg_replace_callback(
'/&\w+;/',
function ($match) {
return str_repeat(' ', strlen($match[0]));
},
$string
);
}
}
4 changes: 2 additions & 2 deletions tests/Source/Filter/HtmlFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class HtmlFilterTest extends TestCase
public function testBasics()
{
$filter = new HtmlFilter();
$html = "<br>foo <a\nhref = '#' title='bar'>\nbaz</a>";
$text = " foo \n bar \nbaz ";
$html = "<br>foo&reg; <a\nhref = '#' title='bar'>\nbaz</a>";
$text = " foo \n bar \nbaz ";
static::assertEquals($text, $filter->filter($html));
}
}

0 comments on commit cd59137

Please sign in to comment.