Bug 1332165 - Trim values for the purposes of 'skipEmptyFields' in _getPasswordFields. r=Dolske a=jcristau
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 23 Jan 2017 23:31:34 -0800
changeset 378069 fee1e9a5de81307c6f059008afd608a9b0a0e976
parent 378068 f851b8e0286b680d8f792d023369e32887d8260c
child 378070 18731e46b2eae085d2a665713acb2d3b03d6b097
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDolske, jcristau
bugs1332165
milestone53.0a2
Bug 1332165 - Trim values for the purposes of 'skipEmptyFields' in _getPasswordFields. r=Dolske a=jcristau 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
@@ -610,17 +610,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"],
     },
   },