Skip to content

Commit

Permalink
1.2.5, check changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico Kaltofen committed Oct 22, 2018
1 parent 7830c7a commit a2e171a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.2.5] - 2018-10-22

### Fixed
- prevent unescape unicode html entities (email obfuscation)

## [1.2.4] - 2018-07-12

### Fixed
Expand Down
20 changes: 15 additions & 5 deletions src/Hyphenator/FrontendHyphenator.php
Expand Up @@ -37,7 +37,7 @@ public function hyphenate($strBuffer)

$arrSkipPages = Config::get('hyphenator_skipPages');

if (null === $objPage || is_array($arrSkipPages) && in_array($objPage->id, $arrSkipPages, true)) {
if (null === $objPage || \is_array($arrSkipPages) && \in_array($objPage->id, $arrSkipPages, true)) {
return $strBuffer;
}

Expand All @@ -56,14 +56,21 @@ function ($matches) {
$strBuffer
);

// prevent unescape unicode html entities (email obfuscation)
$strBuffer = preg_replace('/&(#+[x0-9a-fA-F]+);/', '&_$1;', $strBuffer);

$doc = HtmlPageCrawler::create($strBuffer);
$isHtmlDocument = $doc->isHtmlDocument();

if (false === $isHtmlDocument) {
$doc = HtmlPageCrawler::create(sprintf('<div id="crawler-root">%s</div>', $strBuffer));
}

$cacheEnabled = (bool) Config::get('hyphenator_enableCache');
$cache = [];

$doc->filter(Config::get('hyphenator_tags'))->each(
function ($node, $i) use ($h, &$cache, $cacheEnabled) {
/** @var $node HtmlPageCrawler */
function (HtmlPageCrawler $node, $i) use ($h, &$cache, $cacheEnabled) {
$clone = $node->makeClone(); // make a clone to prevent `Couldn't fetch DOMElement. Node no longer exists`
$html = $clone->html(); // restore nested inserttags that were replaced with %7B or %7D
$cacheKey = $html;
Expand All @@ -89,15 +96,18 @@ function ($node, $i) use ($h, &$cache, $cacheEnabled) {

$html = $matches['content'];
$clone->html(StringUtil::decodeEntities($html));
$node->replaceWith($clone);
$node->replaceWith($clone->saveHTML());

$cache[$cacheKey] = $html;

return $node;
}
);

$strBuffer = $doc->saveHTML();
$strBuffer = false === $isHtmlDocument ? $doc->filter('#crawler-root')->getInnerHtml() : $doc->saveHTML();

// prevent unescape unicode html entities (email obfuscation)
$strBuffer = preg_replace('/&amp;_(#+[x0-9a-fA-F]+);/', '&$1;', $strBuffer);

$strBuffer = preg_replace_callback(
'/####esi:open####(.*)####esi:close####/',
Expand Down
14 changes: 8 additions & 6 deletions tests/Hyphenator/FrontendHyphenatorTest.php
Expand Up @@ -28,7 +28,7 @@ protected function setUp()
{
parent::setUp();

if (!defined('TL_ROOT')) {
if (!\defined('TL_ROOT')) {
\define('TL_ROOT', $this->getFixturesDir());
}

Expand Down Expand Up @@ -86,13 +86,9 @@ public function hyphenationProvider()
{
$GLOBALS['TL_CONFIG']['hyphenator_tags'] = 'h1, h1> a, h2, h2 > a, h3, h3 > a, h4, h4 > a, h5, h5 > a, h6, h6 > a, p';
$GLOBALS['TL_CONFIG']['hyphenator_wordMin'] = 10;
$GLOBALS['TL_CONFIG']['hyphenator_leftMin'] = 5;
$GLOBALS['TL_CONFIG']['hyphenator_rightMin'] = 5;
$GLOBALS['TL_CONFIG']['hyphenator_quality'] = 9;
$GLOBALS['TL_CONFIG']['hyphenator_hyphen'] = '&shy;';
$GLOBALS['TL_CONFIG']['hyphenator_filter'] = 'Simple';
$GLOBALS['TL_CONFIG']['hyphenator_tokenizers'] = ['Whitespace', 'Punctuation'];
$GLOBALS['TL_CONFIG']['hyphenator_skipPages'] = [];
$GLOBALS['TL_CONFIG']['hyphenator_enableCache'] = true;

return [
[
Expand Down Expand Up @@ -143,6 +139,12 @@ public function hyphenationProvider()
$this->getConfig(),
'<p><br> Tel: +49 40 123 45 67<br> Fax: +49 40 123 45 68 <br> {{email::test@test.de} <br><br><a class="more" href="mailto:%7B%7Bemail_url::test@test.de%7D%7D">Kon&shy;tak&shy;tie&shy;ren Sie uns</a></p>',
],
[
'<h1><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#116;&#x65;&#x73;&#x74;&#64;&#x74;&#101;&#115;&#x74;&#46;&#99;&#x6F;&#109;" title="email obfuscation test for test@test.com">&#116;&#x65;&#x73;&#x74;&#64;&#x74;&#101;&#115;&#x74;&#46;&#99;&#x6F;&#109;</a></h1>',
$this->getPage(),
$this->getConfig(),
'<h1><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#116;&#x65;&#x73;&#x74;&#64;&#x74;&#101;&#115;&#x74;&#46;&#99;&#x6F;&#109;" title="email obfuscation test for test@test.com">&#116;&#x65;&#x73;&#x74;&#64;&#x74;&#101;&#115;&#x74;&#46;&#99;&#x6F;&#109;</a></h1>',
],
];
}

Expand Down

0 comments on commit a2e171a

Please sign in to comment.