From 184b51ec56295ff4b37a0ef9a865602cc19b0957 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 9 Mar 2019 23:25:53 -0500 Subject: [PATCH] Move autolink regex in Util\Strings --- src/Content/Text/BBCode.php | 19 +------------------ src/Util/Strings.php | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 2c324a4330..2d1c681f4f 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1268,24 +1268,7 @@ class BBCode extends BaseObject // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text if (!$for_plaintext) { - // Autolink feature (thanks to https://daringfireball.net/2010/07/improved_regex_for_matching_urls) - $autolink_regex = '@(?xi) -(?]+ # Run of non-space, non-()<> - | # or - \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels - | # or - [^\s`!()\[\]{};:\'".,<>?«»“”‘’] # not a space or one of these punct chars - )* -)@'; - $text = preg_replace($autolink_regex, '[url]$1[/url]', $text); + $text = preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text); if ($simple_html == 7) { $text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text); $text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text); diff --git a/src/Util/Strings.php b/src/Util/Strings.php index 55751d8d82..3edc9ba906 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -346,4 +346,30 @@ class Strings return $return; } + + /** + * Returns the regular expression string to match URLs in a given text + * + * @return string + * @see https://daringfireball.net/2010/07/improved_regex_for_matching_urls + */ + public static function autoLinkRegEx() + { + return '@(?xi) +(?]+ # Run of non-space, non-()<> + | # or + \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels + | # or + [^\s`!()\[\]{};:\'".,<>?«»“”‘’] # not a space or one of these punct chars + )* +)@'; + } } -- 2.39.5