mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-12-29 17:00:58 +01:00
Improve validation of 'name' and 'code' parameters for lint messages
Summary: Ref T9145. Fixes T9316. We now require "name" and "code" has a maximum length (currently, this is 32, but the next diff will raise it to 128). Test Plan: - Installed PHPCS. - Hit both the "name" and "code" issues. - Applied this patch. - Got better errors sooner. Reviewers: chad Reviewed By: chad Subscribers: aik099 Maniphest Tasks: T9145, T9316 Differential Revision: https://secure.phabricator.com/D14165
This commit is contained in:
parent
9c056c5cc8
commit
e8a0ebaeff
3 changed files with 42 additions and 8 deletions
|
@ -90,6 +90,23 @@ final class ArcanistLintMessage extends Phobject {
|
|||
}
|
||||
|
||||
public function setCode($code) {
|
||||
$code = (string)$code;
|
||||
|
||||
$maximum_bytes = 128;
|
||||
$actual_bytes = strlen($code);
|
||||
|
||||
if ($actual_bytes > $maximum_bytes) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Parameter ("%s") passed to "%s" when constructing a lint message '.
|
||||
'must be a scalar with a maximum string length of %s bytes, but is '.
|
||||
'%s bytes in length.',
|
||||
$code,
|
||||
'setCode()',
|
||||
new PhutilNumber($maximum_bytes),
|
||||
new PhutilNumber($actual_bytes)));
|
||||
}
|
||||
|
||||
$this->code = $code;
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -217,6 +217,8 @@ abstract class ArcanistLintEngine extends Phobject {
|
|||
|
||||
foreach ($runnable as $linter) {
|
||||
foreach ($linter->getLintMessages() as $message) {
|
||||
$this->validateLintMessage($linter, $message);
|
||||
|
||||
if (!$this->isSeverityEnabled($message->getSeverity())) {
|
||||
continue;
|
||||
}
|
||||
|
@ -598,5 +600,18 @@ abstract class ArcanistLintEngine extends Phobject {
|
|||
$this->endLintServiceCall($call_id);
|
||||
}
|
||||
|
||||
private function validateLintMessage(
|
||||
ArcanistLinter $linter,
|
||||
ArcanistLintMessage $message) {
|
||||
|
||||
$name = $message->getName();
|
||||
if (!strlen($name)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Linter "%s" generated a lint message that is invalid because it '.
|
||||
'does not have a name. Lint messages must have a name.',
|
||||
get_class($linter)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -109,15 +109,17 @@ final class ArcanistPhpcsLinter extends ArcanistExternalLinter {
|
|||
$prefix = 'W';
|
||||
}
|
||||
|
||||
$code = 'PHPCS.'.$prefix.'.'.$child->getAttribute('source');
|
||||
$source = $child->getAttribute('source');
|
||||
$code = 'PHPCS.'.$prefix.'.'.$source;
|
||||
|
||||
$message = new ArcanistLintMessage();
|
||||
$message->setPath($path);
|
||||
$message->setLine($child->getAttribute('line'));
|
||||
$message->setChar($child->getAttribute('column'));
|
||||
$message->setCode($code);
|
||||
$message->setDescription($child->nodeValue);
|
||||
$message->setSeverity($this->getLintMessageSeverity($code));
|
||||
$message = id(new ArcanistLintMessage())
|
||||
->setPath($path)
|
||||
->setName($source)
|
||||
->setLine($child->getAttribute('line'))
|
||||
->setChar($child->getAttribute('column'))
|
||||
->setCode($code)
|
||||
->setDescription($child->nodeValue)
|
||||
->setSeverity($this->getLintMessageSeverity($code));
|
||||
|
||||
$messages[] = $message;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue