From 63cf83e089a962cec3603fac209b33679430e075 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 19 May 2019 13:17:23 +0200 Subject: [PATCH] Linker: Fix fatal error for "/* */" in an edit summary 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 | 8 ++++++++ tests/phpunit/includes/LinkerTest.php | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/includes/Linker.php b/includes/Linker.php index ff4c786110..4d684b5ea1 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1232,6 +1232,14 @@ class Linker { $sectionText = str_replace( '[[', '[[', $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 { diff --git a/tests/phpunit/includes/LinkerTest.php b/tests/phpunit/includes/LinkerTest.php index 2362961ea7..d3523c3a54 100644 --- a/tests/phpunit/includes/LinkerTest.php +++ b/tests/phpunit/includes/LinkerTest.php @@ -278,6 +278,11 @@ class LinkerTest extends MediaWikiLangTestCase { '→‎[[linkie?]]', "/* [[linkie?]] */", ], + [ + '→‎: // Edit via via', + // Regression test for T222857 + "/* */ // Edit via via", + ], [ '→‎autocomment: post', "/* autocomment */ post", -- 2.20.1