From 31ee49b14d931af4a20876fb19d026e30416df6d Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 1 Jun 2018 13:05:46 -0700 Subject: [PATCH] Fix Javascript busy loop when trying to delete tokens from an empty tokenizer Summary: Fixes T13147. In D19437, I changed this logic to support deleting the `""` (empty string) token, but `[].pop()` returns `undefined`, not `null`, if the list is empty and I didn't think to try deleting an empty input. Fix the logic so we don't end up in a loop if the input is empty. Test Plan: - In any browser, deleted all tokens in a tokenizer; then pressed delete again. - Before: tab hangs in an infinte loop. - After: smooth sailing. Reviewers: amckinley, avivey Reviewed By: avivey Maniphest Tasks: T13147 Differential Revision: https://secure.phabricator.com/D19456 --- resources/celerity/map.php | 18 +++++++++--------- .../javelin/lib/control/tokenizer/Tokenizer.js | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 2631b54f8c..dbd9b9c33b 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -10,7 +10,7 @@ return array( 'conpherence.pkg.css' => 'e68cf1fa', 'conpherence.pkg.js' => '15191c65', 'core.pkg.css' => '8be474cc', - 'core.pkg.js' => 'e452721e', + 'core.pkg.js' => '2058ec09', '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' => 'dfaf006b', + 'rsrc/externals/javelin/lib/control/tokenizer/Tokenizer.js' => 'bb6e5c16', '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' => 'dfaf006b', + 'javelin-tokenizer' => 'bb6e5c16', 'javelin-typeahead' => '70baed2f', 'javelin-typeahead-composite-source' => '503e17fd', 'javelin-typeahead-normalizer' => '185bbd53', @@ -1842,6 +1842,12 @@ return array( 'javelin-uri', 'phabricator-notification', ), + 'bb6e5c16' => array( + 'javelin-dom', + 'javelin-util', + 'javelin-stratcom', + 'javelin-install', + ), 'bcaccd64' => array( 'javelin-behavior', 'javelin-behavior-device', @@ -2019,12 +2025,6 @@ return array( 'phuix-icon-view', 'phabricator-prefab', ), - 'dfaf006b' => array( - 'javelin-dom', - 'javelin-util', - 'javelin-stratcom', - 'javelin-install', - ), 'e1d25dfb' => array( 'javelin-behavior', 'javelin-stratcom', diff --git a/webroot/rsrc/externals/javelin/lib/control/tokenizer/Tokenizer.js b/webroot/rsrc/externals/javelin/lib/control/tokenizer/Tokenizer.js index 5e293577aa..2f3dc59a47 100644 --- a/webroot/rsrc/externals/javelin/lib/control/tokenizer/Tokenizer.js +++ b/webroot/rsrc/externals/javelin/lib/control/tokenizer/Tokenizer.js @@ -400,7 +400,8 @@ JX.install('Tokenizer', { // this unusual token. var tok; - while ((tok = this._tokens.pop()) !== null) { + while (this._tokens.length) { + tok = this._tokens.pop(); if (this._remove(tok, true)) { break; }