Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Revert "Make wildcard matches anchored to the ends of the string by d…
Browse files Browse the repository at this point in the history
…efault."

This reverts commit f3ad7b0.

I was banking on few people being affected by this, but people save more searches than I thought.
  • Loading branch information
erikrose committed Jun 27, 2016
1 parent 7f14f4d commit 3144b0c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
9 changes: 2 additions & 7 deletions dxr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,10 @@ def glob_to_regex(glob):
"""Return a regex equivalent to a shell-style glob.
Don't include the regex flags and \\Z at the end like fnmatch.translate(),
because we don't parse flags and JavaScript doesn't support \\Z.
Add ^ to the beginning and $ to the end to ensure that the match is exact
and not just occuring somewhere in the middle of the string. If the user
wants the "match anywhere" behavior they can add a * to the beginning
and/or end of their query term.
because we don't parse flags and we don't want to pin to the end.
"""
return '^' + fnmatch.translate(glob)[:-_FNMATCH_TRANSLATE_SUFFIX_LEN] + '$'
return fnmatch.translate(glob)[:-_FNMATCH_TRANSLATE_SUFFIX_LEN]


def cached(f):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_core_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_bigrams_and_wildcards(self):
'lang': 'js',
'script': '(new RegExp(pattern, flags)).test(doc["path"][0])',
'params': {
'pattern': r'^.*hi.*hork.*\.cp.$',
'pattern': r'.*hi.*hork.*\.cp.',
'flags': 'i'
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_classes_and_capitals(self):
'lang': 'js',
'script': '(new RegExp(pattern, flags)).test(doc["path"][0])',
'params': {
'pattern': r'^fooba[rz]$',
'pattern': r'fooba[rz]',
'flags': ''
}
}
Expand Down
16 changes: 8 additions & 8 deletions tests/test_path_file_filters/test_path_file_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ class PathAndFileFilterTests(DxrInstanceTestCase):

def test_basic_path_results(self):
"""Check that a 'path:' result includes both file and folder matches."""
self.found_files_eq('path:*fish*', ['fish1', 'fishy_folder/fish2',
'fishy_folder/gill', 'folder/fish3',
'folder/fish4'])
self.found_files_eq('path:fish', ['fish1', 'fishy_folder/fish2',
'fishy_folder/gill', 'folder/fish3',
'folder/fish4'])

def test_basic_file_results(self):
"""Check that a 'file:' result includes only file matches."""
self.found_files_eq('file:fish*', ['fish1', 'fishy_folder/fish2',
'folder/fish3', 'folder/fish4'])
self.found_files_eq('file:fish', ['fish1', 'fishy_folder/fish2',
'folder/fish3', 'folder/fish4'])

def test_path_and_file_line_promotion(self):
"""Make sure promotion of a 'path:' or 'file:' filter to a LINE query
works.
"""
self.found_files_eq('path:*fish* fins', ['folder/fish3'])
self.found_files_eq('file:fish* fins', ['folder/fish3'])
self.found_files_eq('path:fish fins', ['folder/fish3'])
self.found_files_eq('file:fish fins', ['folder/fish3'])

# This fails because we currently intentionally exclude folder paths from
# FILE query results - remove the @raises line when that's changed. (Of
Expand All @@ -37,7 +37,7 @@ def test_basic_wildcard(self):
"""Test basic wildcard functionality."""
# 'path:' and 'file:' currently have the same underlying wildcard
# support, so we're spreading out the basic wildcard testing over both.
self.found_files_eq('path:fish?_fo*er/*',
self.found_files_eq('path:fish?_fo*er',
['fishy_folder/fish2', 'fishy_folder/gill'])

self.found_files_eq('file:fish[14]', ['fish1', 'folder/fish4'])
2 changes: 1 addition & 1 deletion tests/test_symlink/test_symlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_file_search(self):
"""Make sure that searching for path:<symlink name> does not return the symlink.
"""
self.found_files_eq('path:*mkd', ['README.mkd'])
self.found_files_eq('path:mkd', ['README.mkd'])

def test_line_search(self):
"""Make sure that searching for contents within the real file does not return duplicates
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_glob_to_regex():
In other words, pin down the behavior of fnmatch.translate().
"""
eq_(glob_to_regex('hi'), '^hi$')
eq_(glob_to_regex('hi'), 'hi')


def test_decode_es_datetime():
Expand Down

0 comments on commit 3144b0c

Please sign in to comment.