Merge "Linker: Fix fatal error for "/* */" in an edit summary"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sun, 19 May 2019 21:37:51 +0000 (21:37 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sun, 19 May 2019 21:37:51 +0000 (21:37 +0000)
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",