Page MenuHomePhabricator

Nulls passed to preg_match in Cite
Closed, ResolvedPublic


MW REL1_29, HHVM 3.12.

Every time you insert a <ref /> tag without name or follow attribute, the following happens:

[error] [745f47691f61604fa5f7b011] [no req]   ErrorException from line 334 of /var/www/wiki/w/extensions/Cite/includes/Cite.php: PHP Warning: preg_match() expects parameter 2 to be string, null given
#0 /var/www/wiki/w/extensions/Cite/includes/Cite.php(334): MWExceptionHandler::handleError(integer, string, string, integer, array, array)
#1 /var/www/wiki/w/extensions/Cite/includes/Cite.php(212): Cite->guardedRef(string, array, Parser)
#2 /var/www/wiki/w/includes/parser/Parser.php(3882): Cite->ref(string, array, Parser, PPFrame_Hash)
#3 /var/www/wiki/w/includes/parser/Preprocessor_Hash.php(1113): Parser->extensionSubstitution(array, PPFrame_Hash)
#4 /var/www/wiki/w/includes/parser/Parser.php(2942): PPFrame_Hash->expand(PPNode_Hash_Tree, integer)
#5 /var/www/wiki/w/includes/parser/Parser.php(1297): Parser->replaceVariables(string)
#6 /var/www/wiki/w/includes/parser/Parser.php(451): Parser->internalParse(string)
#7 /var/www/wiki/w/includes/content/WikitextContent.php(330): Parser->parse(string, Title, ParserOptions, boolean, boolean, integer)
#8 /var/www/wiki/w/includes/content/AbstractContent.php(497): WikitextContent->fillParserOutput(Title, integer, ParserOptions, boolean, ParserOutput)
#9 /var/www/wiki/w/includes/jobqueue/jobs/RefreshLinksJob.php(227): AbstractContent->getParserOutput(Title, integer, ParserOptions, boolean)
#10 /var/www/wiki/w/includes/jobqueue/jobs/RefreshLinksJob.php(118): RefreshLinksJob->runForTitle(Title)
#11 /var/www/wiki/w/includes/jobqueue/JobRunner.php(289): RefreshLinksJob->run()
#12 /var/www/wiki/w/includes/jobqueue/JobRunner.php(189): JobRunner->executeJob(RefreshLinksJob, Wikimedia\Rdbms\LBFactorySimple, BufferingStatsdDataFactory, integer)
#13 /var/www/wiki/w/maintenance/runJobs.php(87): JobRunner->run(array)
#14 /var/www/wiki/w/maintenance/doMaintenance.php(111): RunJobs->execute()
#15 /var/www/wiki/w/maintenance/runJobs.php(119): include(string)
#16 {main}

When those attributes are not set, Cite::refArgs () sets them to null or false. Then Cite::guardedRef () passes them to preg_match (), which expects a string as its second parametre.

An no, this is not an issue of the current HHVM version. preg_match () is not documented to accept anything but string as subject line.

I think than correcting line 334 of Cite/includes/Cite.php from

if ( preg_match( '/^[0-9]+$/', $key ) || preg_match( '/^[0-9]+$/', $follow ) )


if ( $key && preg_match( '/^[0-9]+$/', $key ) || $follow && preg_match( '/^[0-9]+$/', $follow ) )

will fix the issue.

Event Timeline

I think than correcting line 334 of Cite/includes/Cite.php

Thanks for taking a look at the code! You are very welcome to use developer access to submit the proposed code changes as a Git branch directly into Gerrit. If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader. Thanks again!

Change 381616 had a related patch set uploaded (by Gerrit Patch Uploader; owner: Alexander I. Mashin):
[mediawiki/extensions/Cite@master] T177134: Nulls passed to preg_match in Cite

Change 381616 merged by jenkins-bot:
[mediawiki/extensions/Cite@master] T177134: Nulls passed to preg_match in Cite

Umherirrender assigned this task to alex-mashin.
Umherirrender triaged this task as Medium priority.
Umherirrender added a subscriber: Umherirrender.