mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Improve error messages for bad hashtags and project names
Summary: Ref T8509. We currently give you a fairly obtuse error when trying to name a project something like "!!". The error is correct, but not as helpful as it could be. Give users a more specific, more helpful error. Test Plan: {F1042883} Reviewers: chad Reviewed By: chad Maniphest Tasks: T8509 Differential Revision: https://secure.phabricator.com/D14872
This commit is contained in:
parent
33f55a85b0
commit
e2edb1577c
4 changed files with 45 additions and 1 deletions
|
@ -310,7 +310,6 @@ final class PhabricatorProjectCoreTestCase extends PhabricatorTestCase {
|
|||
$slugs = mpull($slugs, 'getSlug');
|
||||
|
||||
$this->assertTrue(in_array($name2, $slugs));
|
||||
|
||||
}
|
||||
|
||||
public function testDuplicateSlugs() {
|
||||
|
|
|
@ -268,6 +268,17 @@ final class PhabricatorProjectTransactionEditor
|
|||
}
|
||||
|
||||
$name = last($xactions)->getNewValue();
|
||||
|
||||
if (!PhabricatorSlug::isValidProjectSlug($name)) {
|
||||
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
||||
$type,
|
||||
pht('Invalid'),
|
||||
pht(
|
||||
'Project names must contain at least one letter or number.'),
|
||||
last($xactions));
|
||||
break;
|
||||
}
|
||||
|
||||
$name_used_already = id(new PhabricatorProjectQuery())
|
||||
->setViewer($this->getActor())
|
||||
->withNames(array($name))
|
||||
|
@ -304,6 +315,27 @@ final class PhabricatorProjectTransactionEditor
|
|||
$slug_xaction = last($xactions);
|
||||
|
||||
$new = $slug_xaction->getNewValue();
|
||||
|
||||
$invalid = array();
|
||||
foreach ($new as $slug) {
|
||||
if (!PhabricatorSlug::isValidProjectSlug($slug)) {
|
||||
$invalid[] = $slug;
|
||||
}
|
||||
}
|
||||
|
||||
if ($invalid) {
|
||||
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
||||
$type,
|
||||
pht('Invalid'),
|
||||
pht(
|
||||
'Hashtags must contain at least one letter or number. %s '.
|
||||
'project hashtag(s) are invalid: %s.',
|
||||
phutil_count($invalid),
|
||||
implode(', ', $invalid)),
|
||||
$slug_xaction);
|
||||
break;
|
||||
}
|
||||
|
||||
$new = $this->normalizeSlugs($new);
|
||||
|
||||
if ($new) {
|
||||
|
|
|
@ -774,6 +774,14 @@ final class PhabricatorUSEnglishTranslation
|
|||
'%s changed project hashtag(s), added %d: %s; removed %d: %s.' =>
|
||||
'%s changed project hashtags, added %3$s; removed %5$s.',
|
||||
|
||||
'Hashtags must contain at least one letter or number. %s '.
|
||||
'project hashtag(s) are invalid: %s.' => array(
|
||||
'Hashtags must contain at least one letter or number. The '.
|
||||
'hashtag "%2$s" is not valid.',
|
||||
'Hashtags must contain at least one letter or number. These '.
|
||||
'hashtags are invalid: %2$s.',
|
||||
),
|
||||
|
||||
'%s added %d project hashtag(s): %s.' => array(
|
||||
array(
|
||||
'%s added a hashtag: %3$s.',
|
||||
|
|
|
@ -8,6 +8,11 @@ final class PhabricatorSlug extends Phobject {
|
|||
return rtrim($slug, '/');
|
||||
}
|
||||
|
||||
public static function isValidProjectSlug($slug) {
|
||||
$slug = self::normalizeProjectSlug($slug);
|
||||
return ($slug != '_');
|
||||
}
|
||||
|
||||
public static function normalize($slug, $hashtag = false) {
|
||||
$slug = preg_replace('@/+@', '/', $slug);
|
||||
$slug = trim($slug, '/');
|
||||
|
|
Loading…
Reference in a new issue