changeset 65b62a8b02c3 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=65b62a8b02c3
description:
Strip only one wildcard
issue11682
review443571003
diffstat:
CHANGELOG | 1 +
trytond/tests/test_tools.py | 20 +++++++++++---------
trytond/tools/misc.py | 19 +++++++++----------
3 files changed, 21 insertions(+), 19 deletions(-)
diffs (120 lines):
diff -r e7b748f98c80 -r 65b62a8b02c3 CHANGELOG
--- a/CHANGELOG Thu Sep 15 21:49:12 2022 +0200
+++ b/CHANGELOG Fri Sep 16 23:36:30 2022 +0200
@@ -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
diff -r e7b748f98c80 -r 65b62a8b02c3 trytond/tests/test_tools.py
--- a/trytond/tests/test_tools.py Thu Sep 15 21:49:12 2022 +0200
+++ b/trytond/tests/test_tools.py Fri Sep 16 23:36:30 2022 +0200
@@ -167,26 +167,26 @@
'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 @@
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 @@
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 @@
for value, result in [
('foo', True),
('%foo bar%', True),
+ ('%%foo bar%', False),
+ ('%foo bar%%', False),
('foo%', False),
('foo_bar', False),
('foo\\_bar', True),
diff -r e7b748f98c80 -r 65b62a8b02c3 trytond/tools/misc.py
--- a/trytond/tools/misc.py Thu Sep 15 21:49:12 2022 +0200
+++ b/trytond/tools/misc.py Fri Sep 16 23:36:30 2022 +0200
@@ -218,19 +218,18 @@
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 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