Page MenuHomePhabricator

D14403.id.diff
No OneTemporary

D14403.id.diff

diff --git a/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php b/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
--- a/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
+++ b/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
@@ -119,6 +119,19 @@
}
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
--- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
+++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
@@ -2177,6 +2177,51 @@
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<PhabricatorApplicationTransaction> 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 )------------------------------------------------------- */

File Metadata

Mime Type
text/plain
Expires
Wed, Jan 22, 12:03 PM (4 h, 8 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7026142
Default Alt Text
D14403.id.diff (2 KB)

Event Timeline