mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
Fix "arc paste" to stop creating pastes with an empty string ("") as the "language"
Summary: See PHI652. When you `echo x | arc paste` today, you end up with a Paste object that has the empty string as its "language". This is normally not valid. Pastes where the language should be autodetected should have the value `null`, not the empty string. This behavior likely changed when `paste.create` got rewritten in terms of `paste.edit`. Adjust the implementation so it only adds the LANGUAGE transaction if there's an actual language. Also, fix an issue where you can't use the "delete" key to delete tokens with the empty string as their value. Test Plan: - Created a paste with `echo x | arc paste`, got a paste in autodetect mode instead of with a bogus language value. - Created a paste with `echo x | arc paste --lang rainbow`, got a rainbow paste. - Deleted an empty string token with the keyboard. - Deleted normal tokens with the keyboard. - Edited subscribers/etc normally with the keyboard and mouse to make sure I didn't ruin anything. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D19437
This commit is contained in:
parent
26c0db8dd7
commit
d280b24239
4 changed files with 36 additions and 13 deletions
|
@ -10,7 +10,7 @@ return array(
|
|||
'conpherence.pkg.css' => 'e68cf1fa',
|
||||
'conpherence.pkg.js' => '15191c65',
|
||||
'core.pkg.css' => '8be474cc',
|
||||
'core.pkg.js' => 'e1f0f7bd',
|
||||
'core.pkg.js' => 'e452721e',
|
||||
'differential.pkg.css' => '06dc617c',
|
||||
'differential.pkg.js' => 'c2ca903a',
|
||||
'diffusion.pkg.css' => 'a2d17c7d',
|
||||
|
@ -259,7 +259,7 @@ return array(
|
|||
'rsrc/externals/javelin/lib/__tests__/URI.js' => '1e45fda9',
|
||||
'rsrc/externals/javelin/lib/__tests__/behavior.js' => '1ea62783',
|
||||
'rsrc/externals/javelin/lib/behavior.js' => '61cbc29a',
|
||||
'rsrc/externals/javelin/lib/control/tokenizer/Tokenizer.js' => '8d3bc1b2',
|
||||
'rsrc/externals/javelin/lib/control/tokenizer/Tokenizer.js' => 'dfaf006b',
|
||||
'rsrc/externals/javelin/lib/control/typeahead/Typeahead.js' => '70baed2f',
|
||||
'rsrc/externals/javelin/lib/control/typeahead/normalizer/TypeaheadNormalizer.js' => '185bbd53',
|
||||
'rsrc/externals/javelin/lib/control/typeahead/source/TypeaheadCompositeSource.js' => '503e17fd',
|
||||
|
@ -710,7 +710,7 @@ return array(
|
|||
'javelin-scrollbar' => '9065f639',
|
||||
'javelin-sound' => '949c0fe5',
|
||||
'javelin-stratcom' => '327f418a',
|
||||
'javelin-tokenizer' => '8d3bc1b2',
|
||||
'javelin-tokenizer' => 'dfaf006b',
|
||||
'javelin-typeahead' => '70baed2f',
|
||||
'javelin-typeahead-composite-source' => '503e17fd',
|
||||
'javelin-typeahead-normalizer' => '185bbd53',
|
||||
|
@ -1573,12 +1573,6 @@ return array(
|
|||
'javelin-stratcom',
|
||||
'javelin-behavior',
|
||||
),
|
||||
'8d3bc1b2' => array(
|
||||
'javelin-dom',
|
||||
'javelin-util',
|
||||
'javelin-stratcom',
|
||||
'javelin-install',
|
||||
),
|
||||
'8d4a8c72' => array(
|
||||
'javelin-install',
|
||||
'javelin-dom',
|
||||
|
@ -2025,6 +2019,12 @@ return array(
|
|||
'phuix-icon-view',
|
||||
'phabricator-prefab',
|
||||
),
|
||||
'dfaf006b' => array(
|
||||
'javelin-dom',
|
||||
'javelin-util',
|
||||
'javelin-stratcom',
|
||||
'javelin-install',
|
||||
),
|
||||
'e1d25dfb' => array(
|
||||
'javelin-behavior',
|
||||
'javelin-stratcom',
|
||||
|
|
|
@ -64,9 +64,12 @@ final class PasteCreateConduitAPIMethod extends PasteConduitAPIMethod {
|
|||
->setTransactionType(PhabricatorPasteTitleTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($title);
|
||||
|
||||
$xactions[] = id(new PhabricatorPasteTransaction())
|
||||
->setTransactionType(PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($language);
|
||||
if (strlen($language)) {
|
||||
$xactions[] = id(new PhabricatorPasteTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($language);
|
||||
}
|
||||
|
||||
$editor = id(new PhabricatorPasteEditor())
|
||||
->setActor($viewer)
|
||||
|
|
|
@ -38,4 +38,20 @@ final class PhabricatorPasteLanguageTransaction
|
|||
$this->renderLanguageValue($this->getNewValue()));
|
||||
}
|
||||
|
||||
public function validateTransactions($object, array $xactions) {
|
||||
$errors = array();
|
||||
|
||||
foreach ($xactions as $xaction) {
|
||||
$new = $xaction->getNewValue();
|
||||
|
||||
if ($new !== null && !strlen($new)) {
|
||||
$errors[] = $this->newInvalidError(
|
||||
pht('Paste language must be null or a nonempty string.'),
|
||||
$xaction);
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -395,8 +395,12 @@ JX.install('Tokenizer', {
|
|||
break;
|
||||
case 'delete':
|
||||
if (!this._focus.value.length) {
|
||||
// In unusual cases, it's possible for us to end up with a token
|
||||
// that has the empty string ("") as a value. Support removal of
|
||||
// this unusual token.
|
||||
|
||||
var tok;
|
||||
while ((tok = this._tokens.pop())) {
|
||||
while ((tok = this._tokens.pop()) !== null) {
|
||||
if (this._remove(tok, true)) {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue