diff --git a/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php b/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php index e20e811b17..3ddfb8bdf7 100644 --- a/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php +++ b/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php @@ -119,6 +119,19 @@ final class PhabricatorPhurlURLEditor } break; case PhabricatorPhurlURLTransaction::TYPE_ALIAS: + $overdrawn = $this->validateIsTextFieldTooLong( + $object->getName(), + $xactions, + 64); + + if ($overdrawn) { + $errors[] = new PhabricatorApplicationTransactionValidationError( + $type, + pht('Alias Too Long'), + pht('The alias can be no longer than 64 characters.'), + nonempty(last($xactions), null)); + } + foreach ($xactions as $xaction) { if ($xaction->getOldValue() != $xaction->getNewValue()) { $new_alias = $xaction->getNewValue(); diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index ec5c227ffa..7d05d5fda4 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -2177,6 +2177,51 @@ abstract class PhabricatorApplicationTransactionEditor return true; } + /** + * Check that text field input isn't longer than a specified length. + * + * A text field input is invalid if the length of the input is longer than a + * specified length. This length can be determined by the space allotted in + * the database, or given arbitrarily. + * This method is intended to make implementing @{method:validateTransaction} + * more convenient: + * + * $overdrawn = $this->validateIsTextFieldTooLong( + * $object->getName(), + * $xactions, + * $field_length); + * + * This will return `true` if the net effect of the object and transactions + * is a field that is too long. + * + * @param wild Current field value. + * @param list Transactions editing the + * field. + * @param integer for maximum field length. + * @return bool True if the field will be too long after edits. + */ + protected function validateIsTextFieldTooLong( + $field_value, + array $xactions, + $length) { + + if ($xactions) { + $new_value_length = phutil_utf8_strlen(last($xactions)->getNewValue()); + if ($new_value_length <= $length) { + return false; + } else { + return true; + } + } + + $old_value_length = phutil_utf8_strlen($field_value); + if ($old_value_length <= $length) { + return false; + } + + return true; + } + /* -( Implicit CCs )------------------------------------------------------- */