From ad700ca7f4ea66f6295aee0039e6d53f72ccb90f Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Tue, 27 Aug 2013 20:55:06 +0200 Subject: [PATCH] Do not mess up page content with leading slashes. If a page title started with a slash, the algorithm to deal with leading capitals would produce a faulty regexp by accessing $escapedTitle[0] and substr($escapedTitle, 1), which would only capture the slash that escapes the slash. Also fix small bug in template detection (make expression non-greedy). --- LinkTitles.body.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/LinkTitles.body.php b/LinkTitles.body.php index fe13c7d..422d954 100755 --- a/LinkTitles.body.php +++ b/LinkTitles.body.php @@ -107,7 +107,7 @@ if ( $wgLinkTitlesSkipTemplates ) { - $templatesDelimiter = '{{.+}}'; + $templatesDelimiter = '{{.+?}}'; } else { $templatesDelimiter = '{{[^|]+?}}|{{.+\|'; }; @@ -122,8 +122,8 @@ ( $wgLinkTitlesParseHeadings ) ? $delimiter = '' : $delimiter = '=+.+?=+|'; $urlPattern = '[a-z]+?\:\/\/(?:\S+\.)+\S+(?:\/.*)?'; $delimiter = '/(' . $delimiter . '\[\[.*?\]\]|' . $templatesDelimiter . - '|\[' . $urlPattern . '\s.+?\]|'. $urlPattern . - '(?=\s|$)|(?<=\b)\S+\@(?:\S+\.)+\S+(?=\b))/i'; + '|\[' . $urlPattern . '\s.+?\]|'. $urlPattern . '(?=\s|$)' . + '|(?<=\b)\S+\@(?:\S+\.)+\S+(?=\b))/i'; $black_list = str_replace( '_', ' ', '("' . implode( '", "',$wgLinkTitlesBlackList ) . '")' ); @@ -177,7 +177,7 @@ $title = str_replace('_', ' ', $row->page_title); if ( $title != $myTitle ) { - LinkTitles::$safeTitle = str_replace( '/', '\/', $title ); + LinkTitles::$safeTitle = $title; // split the string by [[...]] groups // credits to inhan @ StackOverflow for suggesting preg_split @@ -192,7 +192,7 @@ // the title has to be searched for either in a strictly case-sensitive // way, or in a 'fuzzy' way where the first letter of the title may // be either case. - if ( $wgCapitalLinks ) { + if ( $wgCapitalLinks && ( $escapedTitle[0] != '\\' )) { $searchTerm = '((?i)' . $escapedTitle[0] . '(?-i)' . substr($escapedTitle, 1) . ')'; } else {