Strip only one wildcard

issue11682
review443571003
This commit is contained in:
Cédric Krier
2022-09-16 23:36:30 +02:00
parent 93d3bab62a
commit 1fcefeacc9
3 changed files with 21 additions and 19 deletions
+1
View File
@@ -1,3 +1,4 @@
* Strip only one wildcard
* Manage web extension origin as null
* Remove same types restriction on PYSON If
* Allow PYSON size of fields to be None
+11 -9
View File
@@ -167,26 +167,26 @@ class ToolsTestCase(unittest.TestCase):
'Test strip wildcard'
for clause, result in [
('%a%', 'a'),
('%%%%a%%%', 'a'),
('%%a%%', '%a%'),
('\\%a%', '\\%a'),
('\\%a\\%', '\\%a\\%'),
('a', 'a'),
('', ''),
(None, None),
]:
self.assertEqual(
strip_wildcard(clause), result, msg=clause)
with self.subTest(clause=clause):
self.assertEqual(strip_wildcard(clause), result)
def test_strip_wildcard_different_wildcard(self):
'Test strip wildcard with different wildcard'
self.assertEqual(strip_wildcard('___a___', '_'), 'a')
self.assertEqual(strip_wildcard('_a_', '_'), 'a')
def test_lstrip_wildcard(self):
'Test lstrip wildcard'
for clause, result in [
('%a', 'a'),
('%a%', 'a%'),
('%%%%a%', 'a%'),
('%%a%', '%a%'),
('\\%a%', '\\%a%'),
('a', 'a'),
('', ''),
@@ -197,14 +197,14 @@ class ToolsTestCase(unittest.TestCase):
def test_lstrip_wildcard_different_wildcard(self):
'Test lstrip wildcard with different wildcard'
self.assertEqual(lstrip_wildcard('___a', '_'), 'a')
self.assertEqual(lstrip_wildcard('_a', '_'), 'a')
def test_rstrip_wildcard(self):
'Test rstrip wildcard'
for clause, result in [
('a%', 'a'),
('%a%', '%a'),
('%a%%%%%', '%a'),
('%a%%', '%a%'),
('%a\\%', '%a\\%'),
('a', 'a'),
('', ''),
@@ -213,8 +213,8 @@ class ToolsTestCase(unittest.TestCase):
self.assertEqual(
rstrip_wildcard(clause), result, msg=clause)
def test_rstrip_wildcard_diferent_wildcard(self):
self.assertEqual(rstrip_wildcard('a___', '_'), 'a')
def test_rstrip_wildcard_different_wildcard(self):
self.assertEqual(rstrip_wildcard('a_', '_'), 'a')
def test_escape_wildcard(self):
self.assertEqual(
@@ -232,6 +232,8 @@ class ToolsTestCase(unittest.TestCase):
for value, result in [
('foo', True),
('%foo bar%', True),
('%%foo bar%', False),
('%foo bar%%', False),
('foo%', False),
('foo_bar', False),
('foo\\_bar', True),
+9 -10
View File
@@ -218,19 +218,18 @@ def strip_wildcard(string, wildcard='%', escape='\\'):
def lstrip_wildcard(string, wildcard='%'):
"Strip starting wildcard from string"
if not string:
return string
return string.lstrip(wildcard)
if string and string.startswith(wildcard):
string = string[1:]
return string
def rstrip_wildcard(string, wildcard='%', escape='\\'):
"Strip ending wildcard from string"
if not string:
return string
new_string = string.rstrip(wildcard)
if new_string[-1] == escape:
return string
return new_string
if (string
and string.endswith(wildcard)
and not string.endswith(escape + wildcard)):
string = string[:-1]
return string
def escape_wildcard(string, wildcards='%_', escape='\\'):
@@ -246,7 +245,7 @@ def unescape_wildcard(string, wildcards='%_', escape='\\'):
def is_full_text(value, escape='\\'):
escaped = value.strip('%')
escaped = strip_wildcard(value, escape=escape)
escaped = escaped.replace(escape + '%', '').replace(escape + '_', '')
if '%' in escaped or '_' in escaped:
return False