mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
Merge pull request #3731 from cakephp/issue-3656
Fix TextHelper::autoLinkEmail() near HTML Refs #3656
This commit is contained in:
commit
282a5d1cb5
2 changed files with 66 additions and 38 deletions
|
@ -363,54 +363,82 @@ class TextHelperTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testAutoLinkEmails method
|
* Data provider for autoLinkEmail.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testAutoLinkEmails() {
|
public function autoLinkEmailProvider() {
|
||||||
$text = 'This is a test text';
|
return array(
|
||||||
$expected = 'This is a test text';
|
array(
|
||||||
$result = $this->Text->autoLinkUrls($text);
|
'This is a test text',
|
||||||
$this->assertEquals($expected, $result);
|
'This is a test text',
|
||||||
|
),
|
||||||
|
|
||||||
$text = 'email@example.com address';
|
array(
|
||||||
$expected = '<a href="mailto:email@example.com">email@example.com</a> address';
|
'email@example.com address',
|
||||||
$result = $this->Text->autoLinkEmails($text);
|
'<a href="mailto:email@example.com">email@example.com</a> address',
|
||||||
$this->assertEquals($expected, $result);
|
),
|
||||||
|
|
||||||
$text = 'email@example.com address';
|
array(
|
||||||
$expected = '<a href="mailto:email@example.com">email@example.com</a> address';
|
'email@example.com address',
|
||||||
$result = $this->Text->autoLinkEmails($text);
|
'<a href="mailto:email@example.com">email@example.com</a> address',
|
||||||
$this->assertEquals($expected, $result);
|
),
|
||||||
|
|
||||||
$text = '(email@example.com) address';
|
array(
|
||||||
$expected = '(<a href="mailto:email@example.com">email@example.com</a>) address';
|
'(email@example.com) address',
|
||||||
$result = $this->Text->autoLinkEmails($text);
|
'(<a href="mailto:email@example.com">email@example.com</a>) address',
|
||||||
$this->assertEquals($expected, $result);
|
),
|
||||||
|
|
||||||
$text = 'Text with email@example.com address';
|
array(
|
||||||
$expected = 'Text with <a href="mailto:email@example.com">email@example.com</a> address';
|
'Text with email@example.com address',
|
||||||
$result = $this->Text->autoLinkEmails($text);
|
'Text with <a href="mailto:email@example.com">email@example.com</a> address',
|
||||||
$this->assertEquals($expected, $result);
|
),
|
||||||
|
|
||||||
$text = "Text with o'hare._-bob@example.com address";
|
array(
|
||||||
$expected = 'Text with <a href="mailto:o'hare._-bob@example.com">o'hare._-bob@example.com</a> address';
|
"Text with o'hare._-bob@example.com address",
|
||||||
$result = $this->Text->autoLinkEmails($text);
|
'Text with <a href="mailto:o'hare._-bob@example.com">o'hare._-bob@example.com</a> address',
|
||||||
$this->assertEquals($expected, $result);
|
),
|
||||||
|
|
||||||
$text = 'Text with email@example.com address';
|
array(
|
||||||
$expected = 'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address';
|
'Text with düsentrieb@küchenschöhn-not-working.de address',
|
||||||
$result = $this->Text->autoLinkEmails($text, array('class' => 'link'));
|
'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address',
|
||||||
$this->assertEquals($expected, $result);
|
),
|
||||||
|
|
||||||
$text = 'Text with düsentrieb@küchenschöhn-not-working.de address';
|
array(
|
||||||
$expected = 'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address';
|
'Text with me@subdomain.küchenschöhn.de address',
|
||||||
$result = $this->Text->autoLinkEmails($text);
|
'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address',
|
||||||
$this->assertEquals($expected, $result);
|
),
|
||||||
|
|
||||||
$text = 'Text with me@subdomain.küchenschöhn.de address';
|
array(
|
||||||
$expected = 'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address';
|
'Text with email@example.com address',
|
||||||
$result = $this->Text->autoLinkEmails($text);
|
'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address',
|
||||||
|
array('class' => 'link'),
|
||||||
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
'<p>mark@example.com</p>',
|
||||||
|
'<p><a href="mailto:mark@example.com">mark@example.com</a></p>',
|
||||||
|
array('escape' => false)
|
||||||
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
'Some mark@example.com Text',
|
||||||
|
'Some <a href="mailto:mark@example.com">mark@example.com</a> Text',
|
||||||
|
array('escape' => false)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testAutoLinkEmails method
|
||||||
|
*
|
||||||
|
* @param string $text The text to link
|
||||||
|
* @param string $expected The expected results.
|
||||||
|
* @dataProvider autoLinkEmailProvider
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAutoLinkEmails($text, $expected, $attrs = array()) {
|
||||||
|
$result = $this->Text->autoLinkEmails($text, $attrs);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ class TextHelper extends AppHelper {
|
||||||
|
|
||||||
$atom = '[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]';
|
$atom = '[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]';
|
||||||
$text = preg_replace_callback(
|
$text = preg_replace_callback(
|
||||||
'/(?<=\s|^|\()(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui',
|
'/(?<=\s|^|\(|\>|\;)(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui',
|
||||||
array(&$this, '_insertPlaceholder'),
|
array(&$this, '_insertPlaceholder'),
|
||||||
$text
|
$text
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue