banking-addons-team team mailing list archive
-
banking-addons-team team
-
Mailing list archive
-
Message #01634
[Merge] lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-regexp-escape-1287626 into lp:banking-addons/bank-statement-reconcile-7.0
Guewen Baconnier @ Camptocamp has proposed merging lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-regexp-escape-1287626 into lp:banking-addons/bank-statement-reconcile-7.0.
Commit message:
[FIX] too many characters are escaped, leading to an 'invalid regular expression: invalid escape \ sequence' error.
Escape only the list of characters that must be escaped according to POSIX-ARE
Requested reviews:
Banking Addons Core Editors (banking-addons-team)
Related bugs:
Bug #1287626 in Banking Addons: "account_statement_base_completion: invalid regular expression: invalid escape \ sequence"
https://bugs.launchpad.net/banking-addons/+bug/1287626
For more details, see:
https://code.launchpad.net/~camptocamp/banking-addons/bank-statement-reconcile-7.0-regexp-escape-1287626/+merge/209262
Details in bug report lp:1287626
--
https://code.launchpad.net/~camptocamp/banking-addons/bank-statement-reconcile-7.0-regexp-escape-1287626/+merge/209262
Your team Banking Addons Core Editors is requested to review the proposed merge of lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-regexp-escape-1287626 into lp:banking-addons/bank-statement-reconcile-7.0.
=== modified file 'account_statement_base_completion/statement.py'
--- account_statement_base_completion/statement.py 2014-02-21 18:29:07 +0000
+++ account_statement_base_completion/statement.py 2014-03-04 13:23:57 +0000
@@ -319,9 +319,15 @@
if not context['partner_memoizer']:
return res
st_obj = self.pool.get('account.bank.statement.line')
- # regexp_replace(name,'([^a-zA-Z0-9 -])', '\\\1', 'g'), 'i') escape the column name to avoid false positive. (ex 'jho..doe' -> 'joh\.\.doe'
+ # The regexp_replace() escapes the name to avoid false positive
+ # example: 'John J. Doe (No 1)' is escaped to 'John J\. Doe \(No 1\)'
+ # See http://stackoverflow.com/a/400316/1504003 for a list of
+ # chars to escape. Postgres is POSIX-ARE, compatible with
+ # POSIX-ERE excepted that '\' must be escaped inside brackets according to:
+ # http://www.postgresql.org/docs/9.0/static/functions-matching.html
+ # in chapter 9.7.3.6. Limits and Compatibility
sql = """SELECT id FROM (
- SELECT id, regexp_matches(%s, regexp_replace(name,'([^[:alpha:]0-9 -])', %s, 'g'), 'i') AS name_match FROM res_partner
+ SELECT id, regexp_matches(%s, regexp_replace(name,'([\.\^\$\*\+\?\(\)\[\{\\\|])', %s, 'g'), 'i') AS name_match FROM res_partner
WHERE id IN %s) AS res_patner_matcher
WHERE name_match IS NOT NULL"""
cr.execute(sql, (st_line['name'], r"\\\1", context['partner_memoizer']))
=== modified file 'account_statement_base_completion/tests/test_base_completion.py'
--- account_statement_base_completion/tests/test_base_completion.py 2014-02-17 17:24:03 +0000
+++ account_statement_base_completion/tests/test_base_completion.py 2014-03-04 13:23:57 +0000
@@ -36,6 +36,8 @@
name_completion_case("A.one SA", "A.one SA for line", True),
name_completion_case("Acsone SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", False),
name_completion_case("Acsone ([^a-zA-Z0-9 -]) SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", True),
+ name_completion_case(r"Acsone (.^$*+?()[{\| -]\) SA", r"Line for Acsone (.^$*+?()[{\| -]\) SA test", True),
+ name_completion_case("Acšone SA", "Line for Acšone SA test", True),
]
Follow ups