From 3395f5603699aa5a76cadbbea64db4ca8c681f4e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 19 May 2019 08:45:29 -0400 Subject: [PATCH 1/3] Add Unicode support to autolink regular expression - Explicitly exclude non-breaking spaces from URLs as \s doesn't include them --- src/Util/Strings.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Util/Strings.php b/src/Util/Strings.php index b2b710d96f..3f8990d6c1 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -355,25 +355,25 @@ class Strings */ public static function autoLinkRegEx() { - return '@(?xi) + return '@ (??«»“”‘’.] # Domain can\'t start with a . - [^/\s`!()\[\]{};:\'",<>?«»“”‘’]+ # Domain can\'t end with a . + [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’.] # Domain can\'t start with a . + [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’]+ # Domain can\'t end with a . \. - [^/\s`!()\[\]{};:\'".,<>?«»“”‘’]+/? # Followed by a slash + [^/\s\xA0`!()\[\]{};:\'".,<>?«»“”‘’]+/? # Followed by a slash ) (?: # One or more: - [^\s()<>]+ # Run of non-space, non-()<> + [^\s\xA0()<>]+ # Run of non-space, non-()<> | # or - \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels + \(([^\s\xA0()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels | # or - [^\s`!()\[\]{};:\'".,<>?«»“”‘’] # not a space or one of these punct chars + [^\s\xA0`!()\[\]{};:\'".,<>?«»“”‘’] # not a space or one of these punct chars )* -)@'; +)@xiu'; } /** From 325ba20141dfa4a85411cf24ea692ea0174cf5b2 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 19 May 2019 08:45:54 -0400 Subject: [PATCH 2/3] Improve Diaspora raw text support in /babel module --- src/Module/Debug/Babel.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Module/Debug/Babel.php b/src/Module/Debug/Babel.php index 899c8033c4..1ce1ac4c6e 100644 --- a/src/Module/Debug/Babel.php +++ b/src/Module/Debug/Babel.php @@ -7,6 +7,7 @@ use Friendica\Content\Text; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Model\Item; +use Friendica\Util\XML; /** * Translates input text into different formats (HTML, BBCode, Markdown) @@ -98,10 +99,10 @@ class Babel extends BaseModule $markdown = trim($_REQUEST['text']); $results[] = [ 'title' => L10n::t('Source input (Diaspora format)'), - 'content' => '
' . $markdown . '
' + 'content' => '
' . htmlspecialchars($markdown) . '
' ]; - $html = Text\Markdown::convert($markdown); + $html = Text\Markdown::convert(html_entity_decode($markdown,ENT_COMPAT, 'UTF-8')); $results[] = [ 'title' => L10n::t('Markdown::convert (raw HTML)'), 'content' => visible_whitespace(htmlspecialchars($html)) @@ -112,7 +113,7 @@ class Babel extends BaseModule 'content' => $html ]; - $bbcode = Text\Markdown::toBBCode($markdown); + $bbcode = Text\Markdown::toBBCode(XML::unescape($markdown)); $results[] = [ 'title' => L10n::t('Markdown::toBBCode'), 'content' => '
' . $bbcode . '
' From c21a227d0a9509c85cafd7316f631570b12a53c9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 19 May 2019 14:57:28 -0400 Subject: [PATCH 3/3] Add test for bug 7150 --- tests/src/Content/Text/BBCodeTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 802a90278b..864a3794d3 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -109,6 +109,10 @@ class BBCodeTest extends MockedTest 'data' => "http://example.com
    ", 'assertHTML' => false ], + 'bug-7150' => [ + 'data' => html_entity_decode('http://example.com ', ENT_QUOTES, 'UTF-8'), + 'assertHTML' => false + ], ]; }