Detect all wild cards and escaped wild cards in likify
issue10020 review320611002
This commit is contained in:
1 parent
d64b70cce2
commit
663c3a3331
2 files changed
+18
-4
No files matched your search
@@ -98,12 +98,12 @@ def group_operator(tokens):
|
||||
yield cur
|
||||
|
||||
|
||||
def likify(value):
|
||||
def likify(value, escape='\\'):
|
||||
"Add % if needed"
|
||||
if not value:
|
||||
return '%'
|
||||
escaped = value.replace('%%', '__')
|
||||
if '%' in escaped:
|
||||
escaped = value.replace(escape + '%', '').replace(escape + '_', '')
|
||||
if '%' in escaped or '_' in escaped:
|
||||
return value
|
||||
else:
|
||||
return '%' + value + '%'
|
||||
|
||||
@@ -7,7 +7,8 @@ from unittest import TestCase
|
||||
from tryton.common import untimezoned_date
|
||||
from tryton.common.domain_parser import (
|
||||
group_operator, quote, split_target_value, convert_value, format_value,
|
||||
complete_value, parenthesize, rlist, operatorize, DomainParser, udlex)
|
||||
complete_value, parenthesize, rlist, operatorize, DomainParser, udlex,
|
||||
likify)
|
||||
|
||||
|
||||
class DomainParserTestCase(TestCase):
|
||||
@@ -26,6 +27,19 @@ class DomainParserTestCase(TestCase):
|
||||
self.assertEqual(
|
||||
list(group_operator(iter(['a', '>', '=', '=']))), ['a', '>=', '='])
|
||||
|
||||
def test_likify(self):
|
||||
"Test likify"
|
||||
for value, result in [
|
||||
('', '%'),
|
||||
('foo', '%foo%'),
|
||||
('foo%', 'foo%'),
|
||||
('foo_bar', 'foo_bar'),
|
||||
('foo\\%', '%foo\\%%'),
|
||||
('foo\\_bar', '%foo\\_bar%'),
|
||||
]:
|
||||
with self.subTest(value=value):
|
||||
self.assertEqual(likify(value), result)
|
||||
|
||||
def test_quote(self):
|
||||
"Test quote"
|
||||
self.assertEqual(quote('test'), 'test')
|
||||
|
||||
Reference in new issue
Block a user