Repository: spyder-ide/spyder

Issue:
Find In Files: empty "Exclude" field makes all files be excluded
When the "exclude" field on Find In Files is empty, all files seem to be excluded from the search, and the search returns no matches.

I'm running the latest version of the 3.x branch, commit 0d6686e71f74a8d4794ca9f25b5e7e8592669e9d.


Discussion:

Resolving patch:
diff --git a/spyder/widgets/findinfiles.py b/spyder/widgets/findinfiles.py
--- a/spyder/widgets/findinfiles.py
+++ b/spyder/widgets/findinfiles.py
@@ -101,7 +101,8 @@ def initialize(self, path, is_file, exclude,
         self.rootpath = path
         self.python_path = False
         self.hg_manifest = False
-        self.exclude = re.compile(exclude)
+        if exclude:
+            self.exclude = re.compile(exclude)
         self.texts = texts
         self.text_re = text_re
         self.is_file = is_file
@@ -143,14 +144,15 @@ def find_files_in_path(self, path):
                         if self.stopped:
                             return False
                     dirname = os.path.join(path, d)
-                    if re.search(self.exclude, dirname + os.sep):
+                    if self.exclude \
+                       and re.search(self.exclude, dirname + os.sep):
                         dirs.remove(d)
                 for f in files:
                     with QMutexLocker(self.mutex):
                         if self.stopped:
                             return False
                     filename = os.path.join(path, f)
-                    if re.search(self.exclude, filename):
+                    if self.exclude and re.search(self.exclude, filename):
                         continue
                     if is_text_file(filename):
                         self.find_string_in_file(filename)
@@ -557,13 +559,16 @@ def get_options(self, all=False):
         file_search = self.path_selection_combo.is_file_search()
         path = self.path_selection_combo.get_current_searchpath()
 
-        # Finding text occurrences
+        if not exclude_re:
+            items = [fnmatch.translate(item.strip())
+                     for item in exclude.split(",")
+                     if item.strip() != '']
+            exclude = '|'.join(items)
+
+        # Validate regular expressions:
+
         try:
-            if not exclude_re:
-                items = [fnmatch.translate(item.strip())
-                         for item in exclude.split(",")]
-                exclude = '|'.join(items)
-            else:
+            if exclude:
                 exclude = re.compile(exclude)
         except Exception:
             exclude_edit = self.exclude_pattern.lineEdit()


Test patch:
diff --git a/spyder/widgets/tests/test_findinfiles.py b/spyder/widgets/tests/test_findinfiles.py
--- a/spyder/widgets/tests/test_findinfiles.py
+++ b/spyder/widgets/tests/test_findinfiles.py
@@ -146,6 +146,29 @@ def test_exclude_extension_string(qtbot):
     assert files_filtered
 
 
+def test_exclude_extension_empty_regex(qtbot):
+    find_in_files = setup_findinfiles(qtbot, exclude="")
+    find_in_files.set_search_text("spam")
+    find_in_files.find_options.set_directory(osp.join(LOCATION, "data"))
+    find_in_files.find()
+    blocker = qtbot.waitSignal(find_in_files.sig_finished)
+    blocker.wait()
+    matches = process_search_results(find_in_files.result_browser.data)
+    assert expected_results() == matches
+
+
+def test_exclude_extension_string(qtbot):
+    find_in_files = setup_findinfiles(qtbot, exclude="",
+                                      exclude_regexp=False)
+    find_in_files.set_search_text("spam")
+    find_in_files.find_options.set_directory(osp.join(LOCATION, "data"))
+    find_in_files.find()
+    blocker = qtbot.waitSignal(find_in_files.sig_finished)
+    blocker.wait()
+    matches = process_search_results(find_in_files.result_browser.data)
+    assert expected_results() == matches
+
+
 def test_exclude_extension_multiple_string(qtbot):
     find_in_files = setup_findinfiles(qtbot, exclude="*.py, *.cpp",
                                       exclude_regexp=False)