From: <gi...@ma...> - 2009-01-27 16:59:28
|
The branch, master has been updated via 3e8936554a2e8c8654d016617087e4027d25b686 (commit) from e184829bb3f2876b660eb415e755e393361fdf93 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 3e8936554a2e8c8654d016617087e4027d25b686 Author: John Reese <jr...@le...> Date: Tue Jan 27 11:56:57 2009 -0500 Fix #7790: change URL-parsing regex to 'better' handle parentheses and brackets in and at the end of URL's, without gobbling up parentheses and brackets surrounding the URL. ----------------------------------------------------------------------- Summary of changes: core/string_api.php | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) ----------------------------------------------------------------------- commit 3e8936554a2e8c8654d016617087e4027d25b686 Author: John Reese <jr...@le...> Date: Tue Jan 27 11:56:57 2009 -0500 Fix #7790: change URL-parsing regex to 'better' handle parentheses and brackets in and at the end of URL's, without gobbling up parentheses and brackets surrounding the URL. diff --git a/core/string_api.php b/core/string_api.php index 6f82a41..f876033 100644 --- a/core/string_api.php +++ b/core/string_api.php @@ -400,6 +400,8 @@ function string_process_bugnote_link( $p_string, $p_include_anchor = true, $p_de # -------------------- # Detect URLs and email addresses in the string and replace them with href anchors function string_insert_hrefs( $p_string ) { + static $s_url_regex = null; + if( !config_get( 'html_make_links' ) ) { return $p_string; } @@ -411,7 +413,17 @@ function string_insert_hrefs( $p_string ) { } # Find any URL in a string and replace it by a clickable link - $p_string = preg_replace( '/(([[:alpha:]][-+.[:alnum:]]*):\/\/(%[[:digit:]A-Fa-f]{2}|[-_.!~*\';\/?%^\\\\:@&={\|}+$#\(\),\[\][:alnum:]])+)/se', "'<a href=\"'.rtrim('\\1','.').'\">\\1</a> [<a href=\"'.rtrim('\\1','.').'\" target=\"_blank\">^</a>]'", $p_string ); + if ( is_null( $s_url_regex ) ) { + $t_url_chars = '(?:%[[:digit:]A-Fa-f]{2}|[-_.!~*\';\/?%^\\\\:@&={\|}+$#\(\),\[\][:alnum:]])'; + $t_url_chars2 = '(?:%[[:digit:]A-Fa-f]{2}|[-_.!~*\';\/?%^\\\\:@&={\|}+$#,[:alnum:]])'; + + $t_url_part1 = "${t_url_chars}"; + $t_url_part2 = "(?:\(${t_url_chars}*\)|\[${t_url_chars}*\]|${t_url_chars2})"; + + $s_url_regex = "/(([[:alpha:]][-+.[:alnum:]]*):\/\/(${t_url_part1}*?${t_url_part2}+))/se"; + } + + $p_string = preg_replace( $s_url_regex, "'<a href=\"'.rtrim('\\1','.').'\">\\1</a> [<a href=\"'.rtrim('\\1','.').'\" target=\"_blank\">^</a>]'", $p_string ); if( $t_change_quotes ) { ini_set( 'magic_quotes_sybase', true ); } ----------------------------------------------------------------------- -- Mantis Bug Tracker |