mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +01:00
Also coerce "char" for lint messages
Summary: Ref T8921. See similar change in D13695. This expands the scope to also coerce `setChar()`. Test Plan: `arc unit --everything` Reviewers: btrahan Subscribers: epriestley Maniphest Tasks: T8921 Differential Revision: https://secure.phabricator.com/D13737
This commit is contained in:
parent
5fcf7b5a3b
commit
e5946ed1a5
1 changed files with 33 additions and 19 deletions
|
@ -72,24 +72,7 @@ final class ArcanistLintMessage extends Phobject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setLine($line) {
|
public function setLine($line) {
|
||||||
if ($line === null) {
|
$this->line = $this->validateInteger($line, 'setLine');
|
||||||
// This just means that we don't have any line information.
|
|
||||||
} else {
|
|
||||||
// For compatibility, accept digit strings since a lot of linters pass
|
|
||||||
// line numbers that they have parsed from command output or XML, which
|
|
||||||
// won't be properly typed.
|
|
||||||
if (is_string($line) && preg_match('/^\d+\z/', $line)) {
|
|
||||||
$line = (int)$line;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_int($line)) {
|
|
||||||
throw new Exception(
|
|
||||||
pht(
|
|
||||||
'Parameter passed to setLine() must be an integer.'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->line = $line;
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +81,7 @@ final class ArcanistLintMessage extends Phobject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setChar($char) {
|
public function setChar($char) {
|
||||||
$this->char = $char;
|
$this->char = $this->validateInteger($char, 'setChar');
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,4 +225,35 @@ final class ArcanistLintMessage extends Phobject {
|
||||||
return $this->bypassChangedLineFiltering;
|
return $this->bypassChangedLineFiltering;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate an integer-like value, returning a strict integer.
|
||||||
|
*
|
||||||
|
* Further on, the pipeline is strict about types. We want to be a little
|
||||||
|
* less strict in linters themselves, since they often parse command line
|
||||||
|
* output or XML and will end up with string representations of numbers.
|
||||||
|
*
|
||||||
|
* @param mixed Integer or digit string.
|
||||||
|
* @return int Integer.
|
||||||
|
*/
|
||||||
|
private function validateInteger($value, $caller) {
|
||||||
|
if ($value === null) {
|
||||||
|
// This just means that we don't have any information.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings like "234" are fine, coerce them to integers.
|
||||||
|
if (is_string($value) && preg_match('/^\d+\z/', $value)) {
|
||||||
|
$value = (int)$value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_int($value)) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Parameter passed to "%s" must be an integer.',
|
||||||
|
$caller.'()'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue