@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+45 -1
-1
src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php
··· 310 310 $slugs = mpull($slugs, 'getSlug'); 311 311 312 312 $this->assertTrue(in_array($name2, $slugs)); 313 - 314 313 } 315 314 316 315 public function testDuplicateSlugs() {
+32
src/applications/project/editor/PhabricatorProjectTransactionEditor.php
··· 268 268 } 269 269 270 270 $name = last($xactions)->getNewValue(); 271 + 272 + if (!PhabricatorSlug::isValidProjectSlug($name)) { 273 + $errors[] = new PhabricatorApplicationTransactionValidationError( 274 + $type, 275 + pht('Invalid'), 276 + pht( 277 + 'Project names must contain at least one letter or number.'), 278 + last($xactions)); 279 + break; 280 + } 281 + 271 282 $name_used_already = id(new PhabricatorProjectQuery()) 272 283 ->setViewer($this->getActor()) 273 284 ->withNames(array($name)) ··· 304 315 $slug_xaction = last($xactions); 305 316 306 317 $new = $slug_xaction->getNewValue(); 318 + 319 + $invalid = array(); 320 + foreach ($new as $slug) { 321 + if (!PhabricatorSlug::isValidProjectSlug($slug)) { 322 + $invalid[] = $slug; 323 + } 324 + } 325 + 326 + if ($invalid) { 327 + $errors[] = new PhabricatorApplicationTransactionValidationError( 328 + $type, 329 + pht('Invalid'), 330 + pht( 331 + 'Hashtags must contain at least one letter or number. %s '. 332 + 'project hashtag(s) are invalid: %s.', 333 + phutil_count($invalid), 334 + implode(', ', $invalid)), 335 + $slug_xaction); 336 + break; 337 + } 338 + 307 339 $new = $this->normalizeSlugs($new); 308 340 309 341 if ($new) {
+8
src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php
··· 774 774 '%s changed project hashtag(s), added %d: %s; removed %d: %s.' => 775 775 '%s changed project hashtags, added %3$s; removed %5$s.', 776 776 777 + 'Hashtags must contain at least one letter or number. %s '. 778 + 'project hashtag(s) are invalid: %s.' => array( 779 + 'Hashtags must contain at least one letter or number. The '. 780 + 'hashtag "%2$s" is not valid.', 781 + 'Hashtags must contain at least one letter or number. These '. 782 + 'hashtags are invalid: %2$s.', 783 + ), 784 + 777 785 '%s added %d project hashtag(s): %s.' => array( 778 786 array( 779 787 '%s added a hashtag: %3$s.',
+5
src/infrastructure/util/PhabricatorSlug.php
··· 8 8 return rtrim($slug, '/'); 9 9 } 10 10 11 + public static function isValidProjectSlug($slug) { 12 + $slug = self::normalizeProjectSlug($slug); 13 + return ($slug != '_'); 14 + } 15 + 11 16 public static function normalize($slug, $hashtag = false) { 12 17 $slug = preg_replace('@/+@', '/', $slug); 13 18 $slug = trim($slug, '/');