Skip to content

Commit 6d86a41

Browse files
authored
Merge pull request #27 from networkteam/bugfix-link-with-attributes
Bugfix: fix regex for links with attributes after href
2 parents e2a2bbd + 7e3a6f1 commit 6d86a41

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

Classes/Fusion/ConvertEmailLinksImplementation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function evaluate()
5050
return $text;
5151
}
5252
if (!is_string($text)) {
53-
throw new Exception(sprintf('Only strings can be processed by this TypoScript object, given: "%s".', gettype($text)), 1409659552);
53+
throw new Exception(sprintf('Only strings can be processed by this Fusion object, given: "%s".', gettype($text)), 1409659552);
5454
}
5555
$currentContext = $this->getRuntime()->getCurrentContext();
5656
$node = $currentContext['node'];

Resources/Private/Fusion/Prototype/MailObfuscator.fusion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ prototype(Networkteam.Neos:MailObfuscator) {
1818
@class = 'Networkteam\\Neos\\MailObfuscator\\Fusion\\ConvertEmailLinksImplementation'
1919

2020
patternMailTo = '/(href=")mailto:([^"]*)/'
21-
patternMailDisplay = '/(href="mailto:[^"]*">)([^<]*)/'
21+
patternMailDisplay = '/(href="mailto:[^>]*>)([^<]*)/'
2222

2323
value = ${value}
2424
node = ${node}

Tests/Unit/Fusion/ConvertEmailLinksImplementationTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class ConvertEmailLinksImplementationTest extends UnitTestCase
4545
*/
4646
protected $mockNode;
4747

48-
public function setUp()
48+
public function setUp(): void
4949
{
50-
$this->convertEmailLinks = $this->getAccessibleMock(ConvertEmailLinksImplementation::class, ['getValue'], [], '', false);
50+
$this->convertEmailLinks = $this->getAccessibleMock(ConvertEmailLinksImplementation::class, ['fusionValue'], [], '', false);
5151

5252
$this->mockContext = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
5353
$this->mockContext->expects($this->any())->method('getWorkspaceName')->will($this->returnValue('live'));
@@ -63,7 +63,6 @@ public function setUp()
6363
$linkNameConverter->setReplacementString(' (at) ');
6464
$this->convertEmailLinks->_set('linkNameConverter', $linkNameConverter);
6565
$this->convertEmailLinks->_set('mailToHrefConverter', new Mailto2HrefObfuscatingConverter(15));
66-
6766
}
6867

6968
/**
@@ -72,13 +71,20 @@ public function setUp()
7271
*/
7372
public function emailsAreConverted($rawText, $expectedText)
7473
{
75-
$this->convertEmailLinks->expects($this->atLeastOnce())->method('getValue')->will($this->returnValue($rawText));
74+
$this->convertEmailLinks
75+
->expects(self::atLeastOnce())
76+
->method('fusionValue')
77+
->will($this->returnValueMap([
78+
['value', $rawText],
79+
['patternMailTo', '/(href=")mailto:([^"]*)/'],
80+
['patternMailDisplay', '/(href="mailto:[^>]*>)([^<]*)/']
81+
]));
7682

7783
$actualResult = $this->convertEmailLinks->evaluate();
7884
$this->assertSame($expectedText, $actualResult);
7985
}
8086

81-
public function emailTexts()
87+
public function emailTexts(): array
8288
{
8389
return [
8490
'just some text not to touch' => [
@@ -100,6 +106,10 @@ public function emailTexts()
100106
'email address with space at the beginning' => [
101107
'Email <a href="mailto: [email protected]">[email protected]</a>',
102108
'Email <a href="javascript:linkTo_UnCryptMailto(\'ithiOtmpbeat-rdb\', -15)">test (at) example.com</a>'
109+
],
110+
'email address with attributes after href' => [
111+
'Email <a href="mailto: [email protected]" itemprop="email">[email protected]</a>',
112+
'Email <a href="javascript:linkTo_UnCryptMailto(\'ithiOtmpbeat-rdb\', -15)" itemprop="email">test (at) example.com</a>'
103113
]
104114
];
105115
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "neos-plugin",
44
"description": "A email address and link obfuscation plugin for Neos CMS",
55
"require": {
6-
"php": ">=7.0",
6+
"php": ">=7.1",
77
"neos/neos": "^3.0 || ^4.0 || ^5.0 || ^7.0"
88
},
99
"autoload": {

0 commit comments

Comments
 (0)