@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.

Helper method for max text field length and validate alias length

Summary: Ref T8992, Validate alias text field length.

Test Plan: Create Phurl with alias of more than 64 characters. Get error. Reduce length of alias to successfully save Phurl.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin

Maniphest Tasks: T8992

Differential Revision: https://secure.phabricator.com/D14403

+58
+13
src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
··· 119 119 } 120 120 break; 121 121 case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 122 + $overdrawn = $this->validateIsTextFieldTooLong( 123 + $object->getName(), 124 + $xactions, 125 + 64); 126 + 127 + if ($overdrawn) { 128 + $errors[] = new PhabricatorApplicationTransactionValidationError( 129 + $type, 130 + pht('Alias Too Long'), 131 + pht('The alias can be no longer than 64 characters.'), 132 + nonempty(last($xactions), null)); 133 + } 134 + 122 135 foreach ($xactions as $xaction) { 123 136 if ($xaction->getOldValue() != $xaction->getNewValue()) { 124 137 $new_alias = $xaction->getNewValue();
+45
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 2177 2177 return true; 2178 2178 } 2179 2179 2180 + /** 2181 + * Check that text field input isn't longer than a specified length. 2182 + * 2183 + * A text field input is invalid if the length of the input is longer than a 2184 + * specified length. This length can be determined by the space allotted in 2185 + * the database, or given arbitrarily. 2186 + * This method is intended to make implementing @{method:validateTransaction} 2187 + * more convenient: 2188 + * 2189 + * $overdrawn = $this->validateIsTextFieldTooLong( 2190 + * $object->getName(), 2191 + * $xactions, 2192 + * $field_length); 2193 + * 2194 + * This will return `true` if the net effect of the object and transactions 2195 + * is a field that is too long. 2196 + * 2197 + * @param wild Current field value. 2198 + * @param list<PhabricatorApplicationTransaction> Transactions editing the 2199 + * field. 2200 + * @param integer for maximum field length. 2201 + * @return bool True if the field will be too long after edits. 2202 + */ 2203 + protected function validateIsTextFieldTooLong( 2204 + $field_value, 2205 + array $xactions, 2206 + $length) { 2207 + 2208 + if ($xactions) { 2209 + $new_value_length = phutil_utf8_strlen(last($xactions)->getNewValue()); 2210 + if ($new_value_length <= $length) { 2211 + return false; 2212 + } else { 2213 + return true; 2214 + } 2215 + } 2216 + 2217 + $old_value_length = phutil_utf8_strlen($field_value); 2218 + if ($old_value_length <= $length) { 2219 + return false; 2220 + } 2221 + 2222 + return true; 2223 + } 2224 + 2180 2225 2181 2226 /* -( Implicit CCs )------------------------------------------------------- */ 2182 2227