diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-09-30 14:25:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-30 14:25:53 +0200 |
commit | 3512f4461722c9a3c7cf6511232bda156bf91970 (patch) | |
tree | 81db6c1d6f8b970322b5b2bd265bc04ad567fef3 | |
parent | 7c670b39a2505f625066e7d87e1536fc02e9d6fc (diff) | |
parent | 601faf97516a836e4ae57dc4cecb9225c0a04338 (diff) | |
download | Shaarli-3512f4461722c9a3c7cf6511232bda156bf91970.tar.gz Shaarli-3512f4461722c9a3c7cf6511232bda156bf91970.tar.zst Shaarli-3512f4461722c9a3c7cf6511232bda156bf91970.zip |
Merge pull request #976 from ArthurHoaro/hotfix/url-parentheses
Fix parsing for description links with parentheses
-rw-r--r-- | application/LinkUtils.php | 2 | ||||
-rw-r--r-- | tests/LinkUtilsTest.php | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/application/LinkUtils.php b/application/LinkUtils.php index 976474de..267e62cd 100644 --- a/application/LinkUtils.php +++ b/application/LinkUtils.php | |||
@@ -109,7 +109,7 @@ function count_private($links) | |||
109 | */ | 109 | */ |
110 | function text2clickable($text, $redirector = '') | 110 | function text2clickable($text, $redirector = '') |
111 | { | 111 | { |
112 | $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[[:alnum:]]/?)!si'; | 112 | $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[a-z0-9\(\)]/?)!si'; |
113 | 113 | ||
114 | if (empty($redirector)) { | 114 | if (empty($redirector)) { |
115 | return preg_replace($regex, '<a href="$1">$1</a>', $text); | 115 | return preg_replace($regex, '<a href="$1">$1</a>', $text); |
diff --git a/tests/LinkUtilsTest.php b/tests/LinkUtilsTest.php index 7c0d4b0b..c77922ec 100644 --- a/tests/LinkUtilsTest.php +++ b/tests/LinkUtilsTest.php | |||
@@ -103,6 +103,16 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
103 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff'; | 103 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff'; |
104 | $processedText = text2clickable($text, ''); | 104 | $processedText = text2clickable($text, ''); |
105 | $this->assertEquals($expectedText, $processedText); | 105 | $this->assertEquals($expectedText, $processedText); |
106 | |||
107 | $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; | ||
108 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">http://hello.there/is=someone#here(please)</a> otherstuff'; | ||
109 | $processedText = text2clickable($text, ''); | ||
110 | $this->assertEquals($expectedText, $processedText); | ||
111 | |||
112 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; | ||
113 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">http://hello.there/is=someone#here(please)&no</a> otherstuff'; | ||
114 | $processedText = text2clickable($text, ''); | ||
115 | $this->assertEquals($expectedText, $processedText); | ||
106 | } | 116 | } |
107 | 117 | ||
108 | /** | 118 | /** |