Merge lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-regexp-escape-1287626 into lp:banking-addons/bank-statement-reconcile-70

Proposed by Guewen Baconnier @ Camptocamp
Status: Merged
Merged at revision: 144
Proposed branch: lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-regexp-escape-1287626
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 32 lines (+10/-2)
2 files modified
account_statement_base_completion/statement.py (+8/-2)
account_statement_base_completion/tests/test_base_completion.py (+2/-0)
To merge this branch: bzr merge lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-regexp-escape-1287626
Reviewer Review Type Date Requested Status
Laurent Mignon (Acsone) (community) code review, no tests Approve
Sébastien BEAU - http://www.akretion.com code review, no tests Approve
Yannick Vaucher @ Camptocamp code review, no tests Approve
Review via email: mp+209262@code.launchpad.net

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

Description of the change

Details in bug report lp:1287626

To post a comment you must log in.
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

LGTM thanks

review: Approve (code review, no tests)
Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :

LGTM, good work

review: Approve (code review, no tests)
Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote :

LGTM, thanks

review: Approve (code review, no tests)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
319 if not context['partner_memoizer']:319 if not context['partner_memoizer']:
320 return res320 return res
321 st_obj = self.pool.get('account.bank.statement.line')321 st_obj = self.pool.get('account.bank.statement.line')
322 # regexp_replace(name,'([^a-zA-Z0-9 -])', '\\\1', 'g'), 'i') escape the column name to avoid false positive. (ex 'jho..doe' -> 'joh\.\.doe'322 # The regexp_replace() escapes the name to avoid false positive
323 # example: 'John J. Doe (No 1)' is escaped to 'John J\. Doe \(No 1\)'
324 # See http://stackoverflow.com/a/400316/1504003 for a list of
325 # chars to escape. Postgres is POSIX-ARE, compatible with
326 # POSIX-ERE excepted that '\' must be escaped inside brackets according to:
327 # http://www.postgresql.org/docs/9.0/static/functions-matching.html
328 # in chapter 9.7.3.6. Limits and Compatibility
323 sql = """SELECT id FROM (329 sql = """SELECT id FROM (
324 SELECT id, regexp_matches(%s, regexp_replace(name,'([^[:alpha:]0-9 -])', %s, 'g'), 'i') AS name_match FROM res_partner330 SELECT id, regexp_matches(%s, regexp_replace(name,'([\.\^\$\*\+\?\(\)\[\{\\\|])', %s, 'g'), 'i') AS name_match FROM res_partner
325 WHERE id IN %s) AS res_patner_matcher331 WHERE id IN %s) AS res_patner_matcher
326 WHERE name_match IS NOT NULL"""332 WHERE name_match IS NOT NULL"""
327 cr.execute(sql, (st_line['name'], r"\\\1", context['partner_memoizer']))333 cr.execute(sql, (st_line['name'], r"\\\1", context['partner_memoizer']))
328334
=== 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 @@
36 name_completion_case("A.one SA", "A.one SA for line", True),36 name_completion_case("A.one SA", "A.one SA for line", True),
37 name_completion_case("Acsone SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", False),37 name_completion_case("Acsone SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", False),
38 name_completion_case("Acsone ([^a-zA-Z0-9 -]) SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", True),38 name_completion_case("Acsone ([^a-zA-Z0-9 -]) SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", True),
39 name_completion_case(r"Acsone (.^$*+?()[{\| -]\) SA", r"Line for Acsone (.^$*+?()[{\| -]\) SA test", True),
40 name_completion_case("Acšone SA", "Line for Acšone SA test", True),
39 ]41 ]
4042
4143

Subscribers

People subscribed via source and target branches