Linker: Fix fatal error for "/* */" in an edit summary
authorTimo Tijhof <krinklemail@gmail.com>
Sun, 19 May 2019 11:17:23 +0000 (13:17 +0200)
committerKrinkle <krinklemail@gmail.com>
Sun, 19 May 2019 11:20:34 +0000 (11:20 +0000)
Follows-up b6e1e99bec8, which switched the method from Title::makeTitleSafe
to TitleValue. The latter throws fatal on non-string $fragment.

Title::makeTitleSafe, on the other hand, uses makeName(), which casts
$fragment to a string, and ignores if it ends up as empty string
(boolean false becomes empty string and thus did "the right thing").

Bug: T222857
Change-Id: Iecc2140fabd31ef0f193740c7fab0fc698c38e51

includes/Linker.php
tests/phpunit/includes/LinkerTest.php

index ff4c786..4d684b5 100644 (file)
@@ -1232,6 +1232,14 @@ class Linker {
                                                $sectionText = str_replace( '[[', '&#91;[', $auto );
 
                                                $section = substr( Parser::guessSectionNameFromStrippedText( $section ), 1 );
+                                               // Support: HHVM (T222857)
+                                               // The guessSectionNameFromStrippedText method returns a non-empty string
+                                               // that starts with "#". Before PHP 7 (and still on HHVM) substr() would
+                                               // return false if the start offset is the end of the string.
+                                               // On PHP 7+, it gracefully returns empty string instead.
+                                               if ( $section === false ) {
+                                                       $section = '';
+                                               }
                                                if ( $local ) {
                                                        $sectionTitle = new TitleValue( NS_MAIN, '', $section );
                                                } else {
index 2362961..d3523c3 100644 (file)
@@ -278,6 +278,11 @@ class LinkerTest extends MediaWikiLangTestCase {
                                '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#linkie.3F" title="Special:BlankPage">→‎&#91;[linkie?]]</a></span></span>',
                                "/* [[linkie?]] */",
                        ],
+                       [
+                               '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage" title="Special:BlankPage">→‎</a>: </span> // Edit via via</span>',
+                               // Regression test for T222857
+                               "/*  */ // Edit via via",
+                       ],
                        [
                                '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a>: </span> post</span>',
                                "/* autocomment */ post",