Bug 1332165 - Trim values for the purposes of 'skipEmptyFields' in _getPasswordFields. r=Dolske
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 23 Jan 2017 23:31:34 -0800
changeset 331753 ed8b016100297fdd10f45f02ebf0202b91559a23
parent 331752 544e7e4e88bfd82ce8c094ed864303958d7263bc
child 331754 2f89807ca30c474bed545f10c9e52a434f297a71
push id36680
push usermozilla@noorenberghe.ca
push dateTue, 31 Jan 2017 01:32:38 +0000
treeherderautoland@ed8b01610029 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDolske
bugs1332165
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1332165 - Trim values for the purposes of 'skipEmptyFields' in _getPasswordFields. r=Dolske We will no longer prompt to save passwords consisting solely of whitespace. MozReview-Commit-ID: FknB39TCHEa
toolkit/components/passwordmgr/LoginManagerContent.jsm
toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js
--- a/toolkit/components/passwordmgr/LoginManagerContent.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerContent.jsm
@@ -601,17 +601,17 @@ var LoginManagerContent = {
       // Exclude ones matching a `notPasswordSelector`, if specified.
       if (fieldOverrideRecipe && fieldOverrideRecipe.notPasswordSelector &&
           element.matches(fieldOverrideRecipe.notPasswordSelector)) {
         log("skipping password field (id/name is", element.id, " / ",
             element.name + ") due to recipe:", fieldOverrideRecipe);
         continue;
       }
 
-      if (skipEmptyFields && !element.value) {
+      if (skipEmptyFields && !element.value.trim()) {
         continue;
       }
 
       pwFields[pwFields.length] = {
                                     index   : i,
                                     element
                                   };
     }
--- a/toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js
+++ b/toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js
@@ -72,18 +72,28 @@ const TESTCASES = [
   {
     description: "2 password fields outside of a <form> with 1 linked via @form + skipEmpty",
     document: `<input id="pw1" type=password><input id="pw2" type=password form="form1">
       <form id="form1"></form>`,
     returnedFieldIDsByFormLike: [[], []],
     skipEmptyFields: true,
   },
   {
+    description: "skipEmptyFields should also skip white-space only fields",
+    document: `<input id="pw-space" type=password value=" ">
+               <input id="pw-tab" type=password value="	">
+               <input id="pw-newline" type=password form="form1" value="
+">
+      <form id="form1"></form>`,
+    returnedFieldIDsByFormLike: [[], []],
+    skipEmptyFields: true,
+  },
+  {
     description: "2 password fields outside of a <form> with 1 linked via @form + skipEmpty with 1 empty",
-    document: `<input id="pw1" type=password value="pass1"><input id="pw2" type=password form="form1">
+    document: `<input id="pw1" type=password value=" pass1 "><input id="pw2" type=password form="form1">
       <form id="form1"></form>`,
     returnedFieldIDsByFormLike: [["pw1"], []],
     skipEmptyFields: true,
     fieldOverrideRecipe: {
       // Ensure a recipe without `notPasswordSelector` doesn't cause a problem.
       hosts: ["localhost:8080"],
     },
   },