Page MenuHomePhabricator

6458b.patch

Authored By
bzimport
Nov 21 2014, 9:19 PM
Size
2 KB
Referenced Files
None
Subscribers
None

6458b.patch

Index: includes/Parser.php
===================================================================
--- includes/Parser.php (revision 15897)
+++ includes/Parser.php (working copy)
@@ -44,8 +44,10 @@
# Constants needed for external link processing
define( 'HTTP_PROTOCOLS', 'http:\/\/|https:\/\/' );
# Everything except bracket, space, or control characters
define( 'EXT_LINK_URL_CLASS', '[^][<>"\\x00-\\x20\\x7F]' );
+# Everything except bracket, spaces, dashes or control characters (careful, regex is UTF-8)
+define( 'EXT_LINK_FREE_URL', '[^][<>"\\x00-\\x20\\x7F\\x{A0}\\x{2000}-\\x{200B}\\x{200D}-\\x{2015}]' );
# Including space, but excluding newlines
define( 'EXT_LINK_TEXT_CLASS', '[^\]\\x0a\\x0d]' );
define( 'EXT_IMAGE_FNAME_CLASS', '[A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]' );
@@ -1240,7 +1242,7 @@
$protocol = $bits[$i++];
$remainder = $bits[$i++];
- if ( preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $remainder, $m ) ) {
+ if ( preg_match( '/^('.EXT_LINK_FREE_URL.'+)(.*)$/su', $remainder, $m ) ) {
# Found some characters after the protocol that look promising
$url = $protocol . $m[1];
$trail = $m[2];
@@ -1250,7 +1252,7 @@
if(strlen($trail) == 0 &&
isset($bits[$i]) &&
preg_match('/^'. wfUrlProtocols() . '$/S', $bits[$i]) &&
- preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $bits[$i + 1], $m ))
+ preg_match( '/^('.EXT_LINK_FREE_URL.'+)(.*)$/su', $bits[$i + 1], $m ))
{
# add protocol, arg
$url .= $bits[$i] . $m[1]; # protocol, url as arg to previous link
@@ -1266,14 +1268,15 @@
$url = substr($url, 0, $m2[0][1]);
}
- # Move trailing punctuation to $trail
- $sep = ',;\.:!?';
+ # Move trailing punctuation to $trail (2000-2015 are various spaces and dashes)
+ $sep = ',;\\\\\.:!\\?\\x{2000}-\\x{200B}\\x{200D}-\\x{2015}';
# If there is no left bracket, then consider right brackets fair game too
if ( strpos( $url, '(' ) === false ) {
$sep .= ')';
}
- $numSepChars = strspn( strrev( $url ), $sep );
+ preg_match( "/^.*?([$sep]*)$/u", $url, $match );
+ $numSepChars = strlen($match[1]);
if ( $numSepChars ) {
$trail = substr( $url, -$numSepChars ) . $trail;
$url = substr( $url, 0, -$numSepChars );

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2589
Default Alt Text
6458b.patch (2 KB)

Event Timeline