mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
Add a "list<regex>" config option and move regex config to it
Summary: Fixes T3807. Several issues: - Currently, we split config of type `list<string>` on commas, which makes it impossible to enter a regex with a comma in it. - Split on newlines only. - Some of the examples are confusing (provided in JSON instead of the format you actually have to enter them). - Show examples in the same format you should enter text. - We didn't validate regexps. - Introduce `list<regex>` to validate regexes. @hlau: Note that the old config format for the bugtraq stuff implied the delimiters on the regular expression. They are no longer implied. The examples show the correct format. Test Plan: Viewed and edited affected config, hitting error and success cases. Reviewers: btrahan Reviewed By: btrahan CC: hlau, aran Maniphest Tasks: T3807 Differential Revision: https://secure.phabricator.com/D6969
This commit is contained in:
parent
ea0dc5625d
commit
7a39ac43b4
5 changed files with 54 additions and 10 deletions
|
@ -282,7 +282,18 @@ final class PhabricatorConfigEditController
|
||||||
$set_value = (string)$value;
|
$set_value = (string)$value;
|
||||||
break;
|
break;
|
||||||
case 'list<string>':
|
case 'list<string>':
|
||||||
$set_value = $request->getStrList('value');
|
case 'list<regex>':
|
||||||
|
$set_value = phutil_split_lines(
|
||||||
|
$request->getStr('value'),
|
||||||
|
$retain_endings = false);
|
||||||
|
|
||||||
|
foreach ($set_value as $key => $v) {
|
||||||
|
if (!strlen($v)) {
|
||||||
|
unset($set_value[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$set_value = array_values($set_value);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'set':
|
case 'set':
|
||||||
$set_value = array_fill_keys($request->getStrList('value'), true);
|
$set_value = array_fill_keys($request->getStrList('value'), true);
|
||||||
|
@ -364,6 +375,7 @@ final class PhabricatorConfigEditController
|
||||||
case 'bool':
|
case 'bool':
|
||||||
return $value ? 'true' : 'false';
|
return $value ? 'true' : 'false';
|
||||||
case 'list<string>':
|
case 'list<string>':
|
||||||
|
case 'list<regex>':
|
||||||
return implode("\n", nonempty($value, array()));
|
return implode("\n", nonempty($value, array()));
|
||||||
case 'set':
|
case 'set':
|
||||||
return implode("\n", nonempty(array_keys($value), array()));
|
return implode("\n", nonempty(array_keys($value), array()));
|
||||||
|
@ -424,6 +436,10 @@ final class PhabricatorConfigEditController
|
||||||
->setOptions($names);
|
->setOptions($names);
|
||||||
break;
|
break;
|
||||||
case 'list<string>':
|
case 'list<string>':
|
||||||
|
case 'list<regex>':
|
||||||
|
$control = id(new AphrontFormTextAreaControl())
|
||||||
|
->setCaption(pht('Separate values with newlines.'));
|
||||||
|
break;
|
||||||
case 'set':
|
case 'set':
|
||||||
$control = id(new AphrontFormTextAreaControl())
|
$control = id(new AphrontFormTextAreaControl())
|
||||||
->setCaption(pht('Separate values with newlines or commas.'));
|
->setCaption(pht('Separate values with newlines or commas.'));
|
||||||
|
|
|
@ -78,6 +78,34 @@ abstract class PhabricatorApplicationConfigOptions extends Phobject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'list<regex>':
|
||||||
|
$valid = true;
|
||||||
|
if (!is_array($value)) {
|
||||||
|
throw new PhabricatorConfigValidationException(
|
||||||
|
pht(
|
||||||
|
"Option '%s' must be a list of regular expressions, but value ".
|
||||||
|
"is not an array.",
|
||||||
|
$option->getKey()));
|
||||||
|
}
|
||||||
|
if ($value && array_keys($value) != range(0, count($value) - 1)) {
|
||||||
|
throw new PhabricatorConfigValidationException(
|
||||||
|
pht(
|
||||||
|
"Option '%s' must be a list of regular expressions, but the ".
|
||||||
|
"value is a map with unnatural keys.",
|
||||||
|
$option->getKey()));
|
||||||
|
}
|
||||||
|
foreach ($value as $v) {
|
||||||
|
$ok = @preg_match($v, '');
|
||||||
|
if ($ok === false) {
|
||||||
|
throw new PhabricatorConfigValidationException(
|
||||||
|
pht(
|
||||||
|
"Option '%s' must be a list of regular expressions, but the ".
|
||||||
|
"value '%s' is not a valid regular expression.",
|
||||||
|
$option->getKey(),
|
||||||
|
$v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'list<string>':
|
case 'list<string>':
|
||||||
$valid = true;
|
$valid = true;
|
||||||
if (!is_array($value)) {
|
if (!is_array($value)) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ final class PhabricatorDifferentialConfigOptions
|
||||||
"PhutilRemarkupEngineBlockRule")),
|
"PhutilRemarkupEngineBlockRule")),
|
||||||
$this->newOption(
|
$this->newOption(
|
||||||
'differential.whitespace-matters',
|
'differential.whitespace-matters',
|
||||||
'list<string>',
|
'list<regex>',
|
||||||
array(
|
array(
|
||||||
'/\.py$/',
|
'/\.py$/',
|
||||||
'/\.l?hs$/',
|
'/\.l?hs$/',
|
||||||
|
@ -127,14 +127,14 @@ final class PhabricatorDifferentialConfigOptions
|
||||||
"If you set this to true, users won't need to login to view ".
|
"If you set this to true, users won't need to login to view ".
|
||||||
"Differential revisions. Anonymous users will have read-only ".
|
"Differential revisions. Anonymous users will have read-only ".
|
||||||
"access and won't be able to interact with the revisions.")),
|
"access and won't be able to interact with the revisions.")),
|
||||||
$this->newOption('differential.generated-paths', 'list<string>', array())
|
$this->newOption('differential.generated-paths', 'list<regex>', array())
|
||||||
->setSummary(pht("File regexps to treat as automatically generated."))
|
->setSummary(pht("File regexps to treat as automatically generated."))
|
||||||
->setDescription(
|
->setDescription(
|
||||||
pht(
|
pht(
|
||||||
"List of file regexps that should be treated as if they are ".
|
"List of file regexps that should be treated as if they are ".
|
||||||
"generated by an automatic process, and thus get hidden by ".
|
"generated by an automatic process, and thus get hidden by ".
|
||||||
"default in differential."))
|
"default in differential."))
|
||||||
->addExample('["/config\.h$/", "#/autobuilt/#"]', pht("Valid Setting")),
|
->addExample("/config\.h$/\n#/autobuilt/#", pht("Valid Setting")),
|
||||||
$this->newOption('differential.allow-self-accept', 'bool', false)
|
$this->newOption('differential.allow-self-accept', 'bool', false)
|
||||||
->setBoolOptions(
|
->setBoolOptions(
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -73,12 +73,12 @@ final class PhabricatorDiffusionConfigOptions
|
||||||
'URL of external bug tracker used by Diffusion. %s will be '.
|
'URL of external bug tracker used by Diffusion. %s will be '.
|
||||||
'substituted by the bug ID.',
|
'substituted by the bug ID.',
|
||||||
'%BUGID%')),
|
'%BUGID%')),
|
||||||
$this->newOption('bugtraq.logregex', 'list<string>', array())
|
$this->newOption('bugtraq.logregex', 'list<regex>', array())
|
||||||
->addExample(array('\B#([1-9]\d*)\b'), pht('Issue #123'))
|
->addExample(array('/\B#([1-9]\d*)\b/'), pht('Issue #123'))
|
||||||
->addExample(
|
->addExample(
|
||||||
array('[Ii]ssues?:?(\s*,?\s*#\d+)+', '(\d+)'),
|
array('/[Ii]ssues?:?(\s*,?\s*#\d+)+/', '/(\d+)/'),
|
||||||
pht('Issue #123, #456'))
|
pht('Issue #123, #456'))
|
||||||
->addExample(array('(?<!#)\b(T[1-9]\d*)\b'), pht('Task T123'))
|
->addExample(array('/(?<!#)\b(T[1-9]\d*)\b/'), pht('Task T123'))
|
||||||
->setDescription(pht(
|
->setDescription(pht(
|
||||||
'Regular expression to link external bug tracker. See '.
|
'Regular expression to link external bug tracker. See '.
|
||||||
'http://tortoisesvn.net/docs/release/TortoiseSVN_en/'.
|
'http://tortoisesvn.net/docs/release/TortoiseSVN_en/'.
|
||||||
|
|
|
@ -717,13 +717,13 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
||||||
|
|
||||||
$matches = null;
|
$matches = null;
|
||||||
$flags = PREG_SET_ORDER | PREG_OFFSET_CAPTURE;
|
$flags = PREG_SET_ORDER | PREG_OFFSET_CAPTURE;
|
||||||
preg_match_all('('.$bugtraq_re.')', $message, $matches, $flags);
|
preg_match_all($bugtraq_re, $message, $matches, $flags);
|
||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
list($all, $all_offset) = array_shift($match);
|
list($all, $all_offset) = array_shift($match);
|
||||||
|
|
||||||
if ($id_re != '') {
|
if ($id_re != '') {
|
||||||
// Match substrings with bug IDs
|
// Match substrings with bug IDs
|
||||||
preg_match_all('('.$id_re.')', $all, $match, PREG_OFFSET_CAPTURE);
|
preg_match_all($id_re, $all, $match, PREG_OFFSET_CAPTURE);
|
||||||
list(, $match) = $match;
|
list(, $match) = $match;
|
||||||
} else {
|
} else {
|
||||||
$all_offset = 0;
|
$all_offset = 0;
|
||||||
|
|
Loading…
Reference in a new issue