From 7cd640146c99f3134f19edc981df717cb009a55a Mon Sep 17 00:00:00 2001 From: Sami Jaktholm Date: Fri, 9 May 2014 09:15:00 -0400 Subject: [PATCH] Bug 967468 - Webconsole - autocompletion: Consider underscore and dollar as alphanumeric when determining a prefix filter to use. r=robcee --- browser/devtools/webconsole/test/browser.ini | 1 + ...-properties-with-non-alphanumeric-names.js | 42 +++++++++++++++++++ browser/devtools/webconsole/webconsole.js | 4 +- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 browser/devtools/webconsole/test/browser_webconsole_autocomplete-properties-with-non-alphanumeric-names.js diff --git a/browser/devtools/webconsole/test/browser.ini b/browser/devtools/webconsole/test/browser.ini index b5a4a1c5084..3afbfe64c5f 100644 --- a/browser/devtools/webconsole/test/browser.ini +++ b/browser/devtools/webconsole/test/browser.ini @@ -270,6 +270,7 @@ run-if = os == "mac" [browser_webconsole_expandable_timestamps.js] [browser_webconsole_autocomplete_in_debugger_stackframe.js] [browser_webconsole_autocomplete_popup_close_on_tab_switch.js] +[browser_webconsole_autocomplete-properties-with-non-alphanumeric-names.js] [browser_console_hide_jsterm_when_devtools_chrome_enabled_false.js] [browser_webconsole_output_01.js] [browser_webconsole_output_02.js] diff --git a/browser/devtools/webconsole/test/browser_webconsole_autocomplete-properties-with-non-alphanumeric-names.js b/browser/devtools/webconsole/test/browser_webconsole_autocomplete-properties-with-non-alphanumeric-names.js new file mode 100644 index 00000000000..a304db1dc1c --- /dev/null +++ b/browser/devtools/webconsole/test/browser_webconsole_autocomplete-properties-with-non-alphanumeric-names.js @@ -0,0 +1,42 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +"use strict"; + +// Test that properties starting with underscores or dollars can be +// autocompleted (bug 967468). + +function test() { + const TEST_URI = "data:text/html;charset=utf8,test autocompletion with $ or _"; + Task.spawn(runner).then(finishTest); + + function* runner() { + function autocomplete(term) { + let deferred = promise.defer(); + + jsterm.setInputValue(term); + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, deferred.resolve); + + yield deferred.promise; + + ok(popup.itemCount > 0, "There's suggestions for '" + term + "'"); + } + + yield addTab(TEST_URI); + let { jsterm } = yield openConsole(tab); + let popup = jsterm.autocompletePopup; + + jsterm.execute("let testObject = {$$aaab: '', $$aaac: ''}"); + + // Should work with bug 967468. + yield autocomplete("Object.__d"); + yield autocomplete("testObject.$$a"); + + // Here's when things go wrong in bug 967468. + yield autocomplete("Object.__de"); + yield autocomplete("testObject.$$aa"); + } +} diff --git a/browser/devtools/webconsole/webconsole.js b/browser/devtools/webconsole/webconsole.js index 2fe04bd2d80..dd886383bd1 100644 --- a/browser/devtools/webconsole/webconsole.js +++ b/browser/devtools/webconsole/webconsole.js @@ -4292,8 +4292,8 @@ JSTerm.prototype = { if (this._autocompleteQuery && input.startsWith(this._autocompleteQuery)) { let filterBy = input; - // Find the last non-alphanumeric if exists. - let lastNonAlpha = input.match(/[^a-zA-Z0-9][a-zA-Z0-9]*$/); + // Find the last non-alphanumeric other than _ or $ if it exists. + let lastNonAlpha = input.match(/[^a-zA-Z0-9_$][a-zA-Z0-9_$]*$/); // If input contains non-alphanumerics, use the part after the last one // to filter the cache if (lastNonAlpha) {