Page MenuHomePhabricator

`syntax.filemap` does not validate input
Closed, ResolvedPublic

Description

I was just looking at our Phabricator error logs in an attempt to troubleshoot T12531 and notice the following error (a whole bunch of them):

[11-Apr-2017 08:30:03 Australia/Sydney] [2017-04-11 08:30:03] ERROR 2: preg_match(): No ending matching delimiter ')' found at [/usr/src/libphutil/src/markup/syntax/engine/PhutilDefaultSyntaxHighlighterEngine.php:29]
[11-Apr-2017 08:30:03 Australia/Sydney] arcanist(head=master, ref.master=a59cfca5f190), phabricator(head=master, ref.master=d1421bc3a1ee), phlab(head=master, ref.master=84b62e6917ec), phutil(head=master, ref.master=c581e769f10c)
[11-Apr-2017 08:30:03 Australia/Sydney]   #0 preg_match(string, string, NULL) called at [<phutil>/src/markup/syntax/engine/PhutilDefaultSyntaxHighlighterEngine.php:29]
[11-Apr-2017 08:30:03 Australia/Sydney]   #1 PhutilDefaultSyntaxHighlighterEngine::getLanguageFromFilename(string) called at [<phabricator>/src/applications/differential/controller/DifferentialRevisionViewController.php:742]
[11-Apr-2017 08:30:03 Australia/Sydney]   #2 DifferentialRevisionViewController::buildSymbolIndexes(PhabricatorRepository, array) called at [<phabricator>/src/applications/differential/controller/DifferentialRevisionViewController.php:226]
[11-Apr-2017 08:30:03 Australia/Sydney]   #3 DifferentialRevisionViewController::handleRequest(AphrontRequest) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:269]
[11-Apr-2017 08:30:03 Australia/Sydney]   #4 AphrontApplicationConfiguration::processRequest(AphrontRequest, PhutilDeferredLog, AphrontPHPHTTPSink, MultimeterControl) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:181]
[11-Apr-2017 08:30:03 Australia/Sydney]   #5 AphrontApplicationConfiguration::runHTTPRequest(AphrontPHPHTTPSink) called at [<phabricator>/webroot/index.php:17]

I recently added some rules to syntax.filemap and it seems that I ended up entering an invalid regular expression. I think that syntax.filemap should probably be validated before it is saved when edited through the UI. Or perhaps a setup issue should be raised if syntax.filemap is invalid (given that it could be set in local.json or somewhere else).

Event Timeline

  • PhabricatorSyntaxHighlightingConfigOptions defines this option.
  • Change the type from wild to custom:SomeClassName to switch to a custom type validator.
  • The new validator class should subclass PhabricatorConfigJSONOptionType.
  • You can look at PhabricatorKeyringConfigOptionType for a (more complex) example of how to validate a value.
  • Test by trying to change the value to something invalid, you should get an error.
  • You can test a regexp is valid like this:
$ok = preg_match($pattern, '');
if ($ok === false) {
  // The regular expression is invalid.
}