jenkins-bot has submitted this change and it was merged. Change subject: Bug: Fails signature detection with extra long signature ......................................................................
Bug: Fails signature detection with extra long signature There were two different circumstances that could trigger echo's signature detection to fail: multibyte characters in signature, and signatures near $wgMaxSigChars limit that expanded past the limit due to wfEscapeWikiText(). This patch adjusts to use mb_substr to appropriatly handle the multibyte characters, and adds a couple extra charactesr to $wgMaxSigChars to allow for wfEscapeWikiText(). This isn't perfect, but a stricter implementation would require much more work than i think we should spend here. Bug: 73426 Change-Id: Ic51c2bc2a08600f188db13a9a0537f1321c9a655 --- M includes/DiscussionParser.php M tests/phpunit/includes/DiscussionParserTest.php 2 files changed, 32 insertions(+), 6 deletions(-) Approvals: Matthias Mullie: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php index 99a610e..b1db1e4 100644 --- a/includes/DiscussionParser.php +++ b/includes/DiscussionParser.php @@ -161,6 +161,7 @@ foreach ( $links[NS_USER] as $dbk => $page_id ) { $user = User::newFromName( $dbk ); + // we should not add user to 'mention' notification list if // 1. the user name is not valid // 2. the user mentions themselves @@ -668,7 +669,7 @@ * - Second element is the normalised user name. */ static public function getUserFromLine( $line, $timestampPos ) { - global $wgContLang; + global $wgContLang, $wgMaxSigChars; // lifted from Parser::pstPass2 $tc = '[' . Title::legalChars() . ']'; @@ -677,10 +678,19 @@ // [[ns:page]] with optional fragment(#foo) and/or pipe(|bar) $regex = "/\[\[($nc+:$tc+)(?:#.*?)?(?:\\|.*?)?]]/"; + // chop off everything after the timestamp $potentialContext = substr( $line, 0, $timestampPos ); - // only look at the 300 chars preceding the timestamp - $startCheckAt = max( 0, $timestampPos - 300 ); - $context = substr( $potentialContext, -$startCheckAt ); + + // only look at the chars preceding the timestamp that can be part of + // the signature. Note that $wgMaxSigChars is characters and not + // bytes and must be handled with the multibyte string extension. + // + // Additionally, wfEscapeWikiText is run against the signature after + // checking length but before replacing the ~~~~ in page content. For + // this we add a fudge factor of 10 characters, as undoing the + // wfEscapeWikiText is more complicated than we need and hopefully + // this covers most cases. + $context = mb_substr( $potentialContext, -$wgMaxSigChars - 10 ); if ( !preg_match_all( $regex, $context, $matches, PREG_SET_ORDER ) ) { return false; diff --git a/tests/phpunit/includes/DiscussionParserTest.php b/tests/phpunit/includes/DiscussionParserTest.php index 7b0a611..ebef8aa 100644 --- a/tests/phpunit/includes/DiscussionParserTest.php +++ b/tests/phpunit/includes/DiscussionParserTest.php @@ -131,7 +131,7 @@ array( "Beep boop [[User:I_Heart_Spaces]] ([[User_talk:I_Heart_Spaces]]) $ts", array( - 10, + strlen( "Beep boop " ), 'I Heart Spaces' ), ), @@ -139,10 +139,26 @@ array( "Shake n Bake --[[User:Werdna|wer]dna]] $ts", array( - 15, + strlen( "Shake n Bake --" ), 'Werdna', ), ), + + array( + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxã? [[User:Jam]] $ts", + array( + strlen( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxã? " ), + "Jam" + ), + ), + // extra long signature + array( + "{{U|He7d3r}}, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxã? [[User:Reverta-me|<span style=\"font-size:13px; color:blue;font-family:Lucida Handwriting;text-shadow:aqua 5px 3px 12px;\">Aaaaa Bbbbbbb</span>]]'' <sup>[[User Talk:Reverta-me|<font color=\"gold\" face=\"Lucida Calligraphy\">Discussão</font>]]</sup>''</font></sup> $ts", + array( + strlen( "{{U|He7d3r}}, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxã? " ), + 'Reverta-me', + ), + ), ); } -- To view, visit https://gerrit.wikimedia.org/r/173455 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic51c2bc2a08600f188db13a9a0537f1321c9a655 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: He7d3r <he7...@gmail.com> Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits