Bug 1155154 - Part 1 - Fix the check for duplicate filters when one filter is a subtring of another one. r=smaug
authorArnaud Bienner <arnaud.bienner@gmail.com>
Mon, 20 Jul 2015 23:07:59 +0200
changeset 254129 f03577f3c73b61aeea06e9a7ecdcae2de32a6968
parent 254128 076402b442958313e39b3e0c67cc01e42ee6e864
child 254130 21b8a570d156762d06b64c73b5598a828e8e99de
push id29090
push userryanvm@gmail.com
push dateWed, 22 Jul 2015 20:34:12 +0000
treeherdermozilla-central@8650fe82f1cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1155154
milestone42.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 1155154 - Part 1 - Fix the check for duplicate filters when one filter is a subtring of another one. r=smaug
dom/html/HTMLInputElement.cpp
dom/html/test/forms/test_input_file_picker.html
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -7286,17 +7286,24 @@ HTMLInputElement::SetFilePickerFiltersFr
     const nsFilePickerFilter& filterToCheck = filtersCopy[i];
     if (filterToCheck.mFilterMask) {
       continue;
     }
     for (uint32_t j = 0; j < filtersCopy.Length(); ++j) {
       if (i == j) {
         continue;
       }
-      if (FindInReadable(filterToCheck.mFilter, filtersCopy[j].mFilter)) {
+      // Check if this filter's extension list is a substring of the other one.
+      // e.g. if filters are "*.jpeg" and "*.jpeg; *.jpg" the first one should
+      // be removed.
+      // Add an extra "; " to be sure the check will work and avoid cases like
+      // "*.xls" being a subtring of "*.xslx" while those are two differents
+      // filters and none should be removed.
+      if (FindInReadable(filterToCheck.mFilter + NS_LITERAL_STRING(";"),
+                         filtersCopy[j].mFilter + NS_LITERAL_STRING(";"))) {
         // We already have a similar, less restrictive filter (i.e.
         // filterToCheck extensionList is just a subset of another filter
         // extension list): remove this one
         filters.RemoveElement(filterToCheck);
       }
     }
   }
 
--- a/dom/html/test/forms/test_input_file_picker.html
+++ b/dom/html/test/forms/test_input_file_picker.html
@@ -26,16 +26,24 @@
   <input id='j' type='file' accept="audio/*, audio/*, audio/*">
   <input id='k' type="file" accept="image/gif,image/png">
   <input id='l' type="file" accept="image/*,image/gif,image/png">
   <input id='m' type="file" accept="image/gif,image/gif">
   <input id='n' type="file" accept="">
   <input id='o' type="file" accept=".test">
   <input id='p' type="file" accept="image/gif,.csv">
   <input id='q' type="file" accept="image/gif,.gif">
+  <input id='r' type="file" accept=".prefix,.prefixPlusSomething">
+  <input id='s' type="file" accept=".xls,.xlsx">
+  <input id='t' type="file" accept=".mp3,.wav,.flac">
+  <input id='u' type="file" accept=".xls, .xlsx">
+  <input id='v' type="file" accept=".xlsx,  .xls">
+  <input id='w' type="file" accept=".xlsx;  .xls">
+  <input id='x' type="file" accept=".xls,  .xlsx">
+  <input id='y' type="file" accept=".xlsx, .xls">
   <input id='z' type='file' accept="i/am,a,pathological,;,,,,test/case">
   <input id='mix-ref' type="file" accept="image/jpeg">
   <input id='mix' type="file" accept="image/jpeg,.jpg">
   <input id='hidden' hidden type='file'>
   <input id='untrusted-click' type='file'>
   <input id='prevent-default' type='file'>
   <input id='prevent-default-false' type='file'>
   <input id='right-click' type='file'>
@@ -86,16 +94,24 @@ var testData = [["a", 1, MockFilePicker.
                 ["j", 1, MockFilePicker.filterAudio, 1],
                 ["k", 3, "*.gif; *.png", 1],
                 ["l", 4, imageExtensionList + "; " + "*.gif; *.png", 1],
                 ["m", 1, "*.gif", 1],
                 ["n", 0, undefined, 0],
                 ["o", 1, "*.test", 1],
                 ["p", 3, "*.gif; *.csv", 1],
                 ["q", 1, "*.gif", 1],
+                ["r", 3, "*.prefix; *.prefixPlusSomething", 1],
+                ["s", 3, "*.xls; *.xlsx", 1],
+                ["t", 4, "*.mp3; *.wav; *.flac", 1],
+                ["u", 3, "*.xls; *.xlsx", 1],
+                ["v", 3, "*.xlsx; *.xls", 1],
+                ["w", 1, "*.xlsx;  .xls", 1],
+                ["x", 3, "*.xls; *.xlsx", 1],
+                ["y", 3, "*.xlsx; *.xls", 1],
                 ["z", 0, undefined, 0],
                 // Note: mix and mix-ref tests extension lists are checked differently: see SimpleTest.executeSoon below
                 ["mix-ref", undefined, undefined, undefined],
                 ["mix", 1, undefined, 1],
                 ["hidden", 0, undefined, 0],
                 ["untrusted-click", 0, undefined, 0],
                 ["prevent-default", 0, undefined, 0, true],
                 ["prevent-default-false", 0, undefined, 0, true],