Make sure slashes are properly escaped in the search query.

This commit is contained in:
Timo Stollenwerk 2013-06-20 10:46:57 +02:00
parent 82faa75891
commit 169559ddc8
2 changed files with 16 additions and 1 deletions

View File

@ -4,6 +4,11 @@ Changelog
4.0 - unreleased
------------------
- Make sure slashes are properly escaped in the search query. Solr 4.0 added
regular expression support, which means that '/' is now a special character
and must be escaped if searching for literal forward slash.
[timo]
- Implement the getDataOrigin method for the FlareContentListingObject that
plone.app.contentlisting defines and that plone.app.search expects to exist.
[timo]

View File

@ -95,7 +95,12 @@ class Search(object):
elif not value: # solr doesn't like empty fields (+foo:"")
if not name:
continue
logger.info('empty search term form "%s:%s", aborting buildQuery' % (name,value))
logger.info(
'empty search term form "%s:%s", aborting buildQuery' % (
name,
value
)
)
return {}
elif field.class_ == 'solr.BoolField':
if not isinstance(value, (tuple, list)):
@ -135,6 +140,11 @@ class Search(object):
value = '"%s"' % value
else:
value = quote(value)
# Solr 4.0 added regular expression support, which means
# that '/' is now a special character and must be escaped
# if searching for literal forward slash.
if '/' in value:
value = value.replace('/', '\/')
if not value: # don't search for empty strings, even quoted
continue
else: