From f5bca61609b243f19ea8bf26c6ae1a74048b5bcf Mon Sep 17 00:00:00 2001 From: Justin Dolske Date: Tue, 12 May 2009 12:09:18 -0700 Subject: [PATCH] Bug 471906 - Login manager's onblur handler shouldn't do anything when the username is blank. r=gavin --- .../passwordmgr/src/nsLoginManager.js | 13 ++++- .../test/subtst_privbrowsing_4.html | 9 ++-- .../test/test_basic_form_autocomplete.html | 54 +++++++++++++++++-- 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/toolkit/components/passwordmgr/src/nsLoginManager.js b/toolkit/components/passwordmgr/src/nsLoginManager.js index aadb47c88b13..e2924ffd3c36 100644 --- a/toolkit/components/passwordmgr/src/nsLoginManager.js +++ b/toolkit/components/passwordmgr/src/nsLoginManager.js @@ -360,6 +360,13 @@ LoginManager.prototype = { case "blur": var acInputField = event.target; var acForm = acInputField.form; + + // If the username is blank, bail out now -- we don't want + // fillForm() to try filling in a login without a username + // to filter on (bug 471906). + if (!acInputField.value) + return; + // Make sure the username field fillForm will use is the // same field as the autocomplete was activated on. If // not, the DOM has been altered and we'll just give up. @@ -618,9 +625,13 @@ LoginManager.prototype = { var logins = this.findLogins({}, origin, actionOrigin, null); var matchingLogins = []; + // Filter out logins that don't match the search prefix. Also + // filter logins without a username, since that's confusing to see + // in the dropdown and we can't autocomplete them anyway. for (i = 0; i < logins.length; i++) { var username = logins[i].username.toLowerCase(); - if (aSearchString.length <= username.length && + if (username && + aSearchString.length <= username.length && aSearchString.toLowerCase() == username.substr(0, aSearchString.length)) { diff --git a/toolkit/components/passwordmgr/test/subtst_privbrowsing_4.html b/toolkit/components/passwordmgr/test/subtst_privbrowsing_4.html index 328720ea2bdc..796ac202eb26 100644 --- a/toolkit/components/passwordmgr/test/subtst_privbrowsing_4.html +++ b/toolkit/components/passwordmgr/test/subtst_privbrowsing_4.html @@ -16,16 +16,19 @@