znuny / Znuny

Znuny/Znuny LTS is a fork of the ((OTRS)) Community Edition, one of the most flexible web-based ticketing systems used for Customer Service, Help Desk, IT Service Management.
https://www.znuny.org
GNU General Public License v3.0
358 stars 85 forks source link

Bug - Znuny Link detection in HTMLUtils.pm matches non URL parts of a text #101

Closed hanneshal closed 2 years ago

hanneshal commented 3 years ago

Environment

Expected behaviour

If I type create note or write an answer and paste or type a valid link, I expect it to be valid after the submit.

Actual behaviour

If I paste a link, within a sentence like:

Hello please visit our website here: https://www.domain.com/foobar/blub.php.

And the user submits this the link is detected, incl. the "." at the end. Which results in an error.

The source of this problem is in https://github.com/znuny/Znuny/blob/rel-6_1-dev/Kernel/System/HTMLUtils.pm#L926 (and above).

A diff with a simple hotfix is attached:

diff --git a/Kernel/System/HTMLUtils.pm b/Kernel/System/HTMLUtils.pm
index 1bdb932146..98b05d8739 100644
--- a/Kernel/System/HTMLUtils.pm
+++ b/Kernel/System/HTMLUtils.pm
@@ -923,6 +923,10 @@ sub LinkQuote {
             $DisplayLink .= $Link;
             $HrefLink    .= $Link;
         }
+
+        # remove trailing dots in href link
+        $HrefLink =~ s{\.+\z}{};
+
         $Start . "<a href=\"$HrefLink\"$Target title=\"$HrefLink\">$DisplayLink<\/a>" . $End;
     }egxism;

diff --git a/scripts/test/HTMLUtils/LinkQuote.t b/scripts/test/HTMLUtils/LinkQuote.t
index f0857f34a7..5236db48db 100644
--- a/scripts/test/HTMLUtils/LinkQuote.t
+++ b/scripts/test/HTMLUtils/LinkQuote.t
@@ -163,6 +163,13 @@ my @Tests = (
         Name   => 'LinkQuote with plain domains.',
         Target => '',
     },
+    {
+        Input => '<html>www.heise.de.</html>',
+        Result =>
+            '<html><a href="http://www.heise.de" title="http://www.heise.de">www.heise.de.</a></html>',
+        Name   => 'LinkQuote with plain domains.',
+        Target => '',
+    },
     {
         Input  => '<html>xwww.heise.de</html>',
         Result => '<html>xwww.heise.de</html>',
@@ -190,6 +197,13 @@ my @Tests = (
         Name   => 'LinkQuote with plain domains with a dash.',
         Target => '',
     },
+    {
+        Input => '<html>www.heise-online.de/Suffix.</html>',
+        Result =>
+            '<html><a href="http://www.heise-online.de/Suffix" title="http://www.heise-online.de/Suffix">www.heise-online.de/Suffix.</a></html>',
+        Name   => 'LinkQuote with plain domains with a dash.',
+        Target => '',
+    },
     {
         Input => '<html>ftp.heise.de/Suffix</html>',
         Result =>

I recommend to re evaluate the logic behind this and also check why the "autolink" of the CKEditor is not used in this case.

How to reproduce

Steps to reproduce the behaviour:

  1. Create a note
  2. Make sure RichText is active
  3. Paste a link in between regular text and append a "." at the end
  4. Submit
  5. Link includes the dot -> which results in an invalid link (in the most cases). We know that a dot is accepted on root level.

Additional information

Screenshots

rkaldung commented 2 years ago

Fixed with 64aa443dc5d4dfc14db58b632f6c9e299074ca70 (dev) and ea35a4bf78278ba6afee613da4e05bf1b7330514 (rel-6_0-dev)