From 6057de2b9d8681dc806ff7809eea35b0afe3750a Mon Sep 17 00:00:00 2001 From: danij Date: Tue, 4 Sep 2012 09:45:09 +0100 Subject: [PATCH] Homepage|Build Repository: Fixed URL rewriting in commit messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced the commit message URL rewriting rules with a set derived from Søren Løvborg's UrlLinker, cheers! (See: http://www.kwi.dk/projects/php/UrlLinker/) --- web/includes/utilities.inc.php | 14 +++++++++----- web/plugins/buildrepository/commitutils.php | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/web/includes/utilities.inc.php b/web/includes/utilities.inc.php index c4b1b66115..02de24fe01 100644 --- a/web/includes/utilities.inc.php +++ b/web/includes/utilities.inc.php @@ -230,7 +230,7 @@ function json_encode_clean(&$array, $flags=0, $indent_level=0) return $result; } -function generateHyperlinkHTML($uri, $maxLength=40, $cssClass=NULL) +function generateHyperlinkHTML($uri, $attributes = array(), $maxLength = 40) { if($uri instanceof Url) { @@ -257,11 +257,15 @@ function generateHyperlinkHTML($uri, $maxLength=40, $cssClass=NULL) else $shortUri = $uri; - $html = ' 0) + $attribs = ''; + if(is_array($attributes)) { - $html .= " class={$cssClass}"; + foreach($attributes as $attribute => $value) + { + $attribs .= " {$attribute}=\"{$value}\""; + } } - $html .= " href=\"{$uri}\">". htmlspecialchars($shortUri) .''; + + $html = "". htmlspecialchars($shortUri) .''; return $html; } diff --git a/web/plugins/buildrepository/commitutils.php b/web/plugins/buildrepository/commitutils.php index cef949d025..08568f0b52 100644 --- a/web/plugins/buildrepository/commitutils.php +++ b/web/plugins/buildrepository/commitutils.php @@ -79,7 +79,7 @@ function make_pretty_hyperlink($matches) $uri->setScheme()->setHost(); } - return generateHyperlinkHTML($uri, 40, $isExternal? 'link-external' : NULL); + return generateHyperlinkHTML($uri, $isExternal? array('class'=>'link-external') : NULL, 40); } function formatCommitHTML($msg) @@ -89,7 +89,19 @@ function formatCommitHTML($msg) // Process the commit message, replacing web URIs with clickable links. htmlspecialchars($msg); - $msg = preg_replace_callback('/((?:[\w\d]+\:\/\/)?(?:[\w\-\d]+\.)+[\w\-\d]+(?:\/[\w\-\d]+)*(?:\/|\.[\w\-\d]+)?(?:\?[\w\-\d]+\=[\w\-\d]+\&?)?(?:\#[\w\-\d]*)?)/', + // Rules derived from Søren Løvborg's UrlLinker (see: http://www.kwi.dk/projects/php/UrlLinker/) + $rexProtocol = '((http|https|ftp)\:\/\/)'; + $rexDomain = '(?:[-a-zA-Z0-9]{1,63}\.)+[a-zA-Z][-a-zA-Z0-9]{1,62}'; + $rexIp = '(?:[1-9][0-9]{0,2}\.|0\.){3}(?:[1-9][0-9]{0,2}|0)'; + $rexPort = '(:[0-9]{1,5})?'; + $rexPath = '(/[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]*?)?'; + $rexQuery = '(\?[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?'; + $rexFragment = '(#[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?'; + $rexUsername = '[^]\\\\\x00-\x20\"(),:-<>[\x7f-\xff]{1,64}'; + $rexPassword = $rexUsername; // allow the same characters as in the username + $rexUrl = "$rexProtocol(?:($rexUsername)(:$rexPassword)?@)?($rexDomain|$rexIp)($rexPort$rexPath$rexQuery$rexFragment)"; + + $msg = preg_replace_callback("&\\b$rexUrl(?=[?.!,;:\"]?(\s|$))&", "make_pretty_hyperlink", $msg); return $msg;