Commit 27eddd73 authored by Tristan Cavelier's avatar Tristan Cavelier

put double quotes if necessary

parent fb0ecb5f
...@@ -34,6 +34,7 @@ from Products.ZSQLCatalog.interfaces.operator import IOperator ...@@ -34,6 +34,7 @@ from Products.ZSQLCatalog.interfaces.operator import IOperator
from Products.ZSQLCatalog.Utils import sqlquote as escapeString from Products.ZSQLCatalog.Utils import sqlquote as escapeString
from zope.interface.verify import verifyClass from zope.interface.verify import verifyClass
from zope.interface import implements from zope.interface import implements
import re
def valueFloatRenderer(value): def valueFloatRenderer(value):
if isinstance(value, basestring): if isinstance(value, basestring):
...@@ -65,11 +66,19 @@ value_search_text_renderer = { ...@@ -65,11 +66,19 @@ value_search_text_renderer = {
DateTime: str, DateTime: str,
} }
# Allows all ascii chars except query syntax special chars.
# In other words it forbids operator chars !<=> as first character
# plus forbids any other syntax special chars like : or space.
raw_string_validator_re = re.compile(r"^[#\$%&'\*\+,\-\./0-9;\?@A-Z\[\\\]\^_`a-z\{\|\}~][!#\$%&'\*\+,\-\./0-9;<=>\?@A-Z\[\\\]\^_`a-z\{\|\}~]*$")
def valueDefaultSearchTextRenderer(value): def valueDefaultSearchTextRenderer(value):
""" """
This is just repr, but always surrounding text strings with doublequotes. This is just repr, but always surrounding text strings with doublequotes.
""" """
if isinstance(value, basestring): if isinstance(value, basestring):
if raw_string_validator_re.match(value):
result = value
else:
if value.replace("\\\\", "")[-1] == "\\": if value.replace("\\\\", "")[-1] == "\\":
value = value[:-1] value = value[:-1]
result = '"{}"'.format(value.replace('"', '\\"')) result = '"{}"'.format(value.replace('"', '\\"'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment