diff options
author | Cash Costello <cash.costello@gmail.com> | 2013-04-20 11:07:44 -0400 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2013-04-20 11:07:44 -0400 |
commit | 834c4ad0bf82f28949b108eb6c957fde3c18e1ce (patch) | |
tree | 5ab3221c111f7acda38fff85c4d602a5375e172a /engine/lib/output.php | |
parent | 39886afeec37309963be57551699c7bfc3f6c37b (diff) | |
download | elgg-834c4ad0bf82f28949b108eb6c957fde3c18e1ce.tar.gz elgg-834c4ad0bf82f28949b108eb6c957fde3c18e1ce.tar.bz2 |
Fixes #5369 allows ! in urls and adds unit tests
Diffstat (limited to 'engine/lib/output.php')
-rw-r--r-- | engine/lib/output.php | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/engine/lib/output.php b/engine/lib/output.php index c5a04989b..fe5bbcaaf 100644 --- a/engine/lib/output.php +++ b/engine/lib/output.php @@ -13,28 +13,33 @@ * @param string $text The input string * * @return string The output string with formatted links - **/ + */ function parse_urls($text) { + + // URI specification: http://www.ietf.org/rfc/rfc3986.txt + // This varies from the specification in the following ways: + // * Supports non-ascii characters + // * Does not allow parentheses and single quotes + // * Cuts off commas, exclamation points, and periods off as last character + // @todo this causes problems with <attr = "val"> // must be in <attr="val"> format (no space). // By default htmlawed rewrites tags to this format. // if PHP supported conditional negative lookbehinds we could use this: // $r = preg_replace_callback('/(?<!=)(?<![ ])?(?<!["\'])((ht|f)tps?:\/\/[^\s\r\n\t<>"\'\!\(\),]+)/i', - // - // we can put , in the list of excluded char but need to keep . because of domain names. - // it is removed in the callback. - $r = preg_replace_callback('/(?<!=)(?<!["\'])((ht|f)tps?:\/\/[^\s\r\n\t<>"\'\!\(\),]+)/i', + $r = preg_replace_callback('/(?<!=)(?<!["\'])((ht|f)tps?:\/\/[^\s\r\n\t<>"\'\(\)]+)/i', create_function( '$matches', ' $url = $matches[1]; - $period = \'\'; - if (substr($url, -1, 1) == \'.\') { - $period = \'.\'; - $url = trim($url, \'.\'); + $punc = \'\'; + $last = substr($url, -1, 1); + if (in_array($last, array(".", "!", ","))) { + $punc = $last; + $url = rtrim($url, ".!,"); } $urltext = str_replace("/", "/<wbr />", $url); - return "<a href=\"$url\">$urltext</a>$period"; + return "<a href=\"$url\">$urltext</a>$punc"; ' ), $text); |