From d9e564d2b6b6cf5ee7b28b6ab577a4ab8b3fe49c Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 30 Jan 2014 11:58:13 -0600
Subject: [PATCH] Prepend `http://` to links starting with `www.`

---
 include/class.format.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/class.format.php b/include/class.format.php
index 03b0a9647..459071018 100644
--- a/include/class.format.php
+++ b/include/class.format.php
@@ -318,11 +318,14 @@ class Format {
                    .'|(\b[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4})`',
                     function ($match) use ($token) {
                         if ($match[1]) {
-                            if (in_array(substr($match[1], -1),
+                            while (in_array(substr($match[1], -1),
                                     array('.','?','-',':',';'))) {
-                                $match[9] = substr($match[1], -1);
+                                $match[9] = substr($match[1], -1) . $match[9];
                                 $match[1] = substr($match[1], 0, strlen($match[1])-1);
                             }
+                            if (strpos($match[2], '//') === false) {
+                                $match[1] = 'http://' . $match[1];
+                            }
                             return '<a href="l.php?url='.urlencode($match[1])
                                 .sprintf('&auth=%s" target="_blank">', $token)
                                 .$match[1].'</a>'.$match[9];
-- 
GitLab