From df81d79d77f89dfd27529a10c2a0aab6020638c5 Mon Sep 17 00:00:00 2001 From: Austin McKinley Date: Thu, 14 Sep 2017 11:24:36 -0700 Subject: [PATCH] Add explicit limits to unit test/lint error names Summary: Fixes T12981. See new `arc lint` output: P2071 See new `arc unit` output: P2072 Test Plan: Ran `arc unit/lint/diff` and observed new error instead of a Conduit error Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T12981 Differential Revision: https://secure.phabricator.com/D18603 --- src/lint/ArcanistLintMessage.php | 15 +++++++++++++++ src/unit/ArcanistUnitTestResult.php | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/lint/ArcanistLintMessage.php b/src/lint/ArcanistLintMessage.php index 7be1d52d..c92c5ec8 100644 --- a/src/lint/ArcanistLintMessage.php +++ b/src/lint/ArcanistLintMessage.php @@ -126,6 +126,21 @@ final class ArcanistLintMessage extends Phobject { } public function setName($name) { + $maximum_bytes = 255; + $actual_bytes = strlen($name); + + if ($actual_bytes > $maximum_bytes) { + throw new Exception( + pht( + 'Parameter ("%s") passed to "%s" when constructing a lint message '. + 'must be a string with a maximum length of %s bytes, but is %s '. + 'bytes in length.', + $name, + 'setName()', + new PhutilNumber($maximum_bytes), + new PhutilNumber($actual_bytes))); + } + $this->name = $name; return $this; } diff --git a/src/unit/ArcanistUnitTestResult.php b/src/unit/ArcanistUnitTestResult.php index a9061bd0..ec25c20f 100644 --- a/src/unit/ArcanistUnitTestResult.php +++ b/src/unit/ArcanistUnitTestResult.php @@ -30,6 +30,20 @@ final class ArcanistUnitTestResult extends Phobject { } public function setName($name) { + $maximum_bytes = 255; + $actual_bytes = strlen($name); + + if ($actual_bytes > $maximum_bytes) { + throw new Exception( + pht( + 'Parameter ("%s") passed to "%s" when constructing a unit test '. + 'message must be a string with a maximum length of %s bytes, but '. + 'is %s bytes in length.', + $name, + 'setName()', + new PhutilNumber($maximum_bytes), + new PhutilNumber($actual_bytes))); + } $this->name = $name; return $this; }