Changeset - 552f6738ace2
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2019-11-20 12:55:14
mads@kiilerich.com
search: avoid crash when making (odd) search for '*'

Crashed in whoosh ListMatcher.supports() on
def supports(self, astype):
return self._format.supports(astype)
with
AttributeError: 'NoneType' object has no attribute 'supports'
on for example http://localhost:5000/_admin/search?q=*&type=content .

There doesn't seem to be a good way to detect if _format has been provided.
1 file changed with 5 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/indexers/__init__.py
Show inline comments
 
@@ -209,13 +209,17 @@ class WhooshResultWrapper(object):
 
        """
 
        Smart function that implements chunking the content
 
        but not overlap chunks so it doesn't highlight the same
 
        close occurrences twice.
 
        """
 
        memory = [(0, 0)]
 
        if self.matcher.supports('positions'):
 
        try:
 
            supports_positions = self.matcher.supports('positions')
 
        except AttributeError:  # 'NoneType' object has no attribute 'supports' (because matcher never get a format)
 
            supports_positions = False
 
        if supports_positions:
 
            for span in self.matcher.spans():
 
                start = span.startchar or 0
 
                end = span.endchar or 0
 
                start_offseted = max(0, start - self.fragment_size)
 
                end_offseted = end + self.fragment_size
 

	
0 comments (0 inline, 0 general)