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
1=== modified file 'account_statement_base_completion/statement.py'
2--- account_statement_base_completion/statement.py 2014-02-21 18:29:07 +0000
3+++ account_statement_base_completion/statement.py 2014-03-04 13:23:57 +0000
4@@ -319,9 +319,15 @@
5 if not context['partner_memoizer']:
6 return res
7 st_obj = self.pool.get('account.bank.statement.line')
8- # regexp_replace(name,'([^a-zA-Z0-9 -])', '\\\1', 'g'), 'i') escape the column name to avoid false positive. (ex 'jho..doe' -> 'joh\.\.doe'
9+ # The regexp_replace() escapes the name to avoid false positive
10+ # example: 'John J. Doe (No 1)' is escaped to 'John J\. Doe \(No 1\)'
11+ # See http://stackoverflow.com/a/400316/1504003 for a list of
12+ # chars to escape. Postgres is POSIX-ARE, compatible with
13+ # POSIX-ERE excepted that '\' must be escaped inside brackets according to:
14+ # http://www.postgresql.org/docs/9.0/static/functions-matching.html
15+ # in chapter 9.7.3.6. Limits and Compatibility
16 sql = """SELECT id FROM (
17- SELECT id, regexp_matches(%s, regexp_replace(name,'([^[:alpha:]0-9 -])', %s, 'g'), 'i') AS name_match FROM res_partner
18+ SELECT id, regexp_matches(%s, regexp_replace(name,'([\.\^\$\*\+\?\(\)\[\{\\\|])', %s, 'g'), 'i') AS name_match FROM res_partner
19 WHERE id IN %s) AS res_patner_matcher
20 WHERE name_match IS NOT NULL"""
21 cr.execute(sql, (st_line['name'], r"\\\1", context['partner_memoizer']))
22
23=== modified file 'account_statement_base_completion/tests/test_base_completion.py'
24--- account_statement_base_completion/tests/test_base_completion.py 2014-02-17 17:24:03 +0000
25+++ account_statement_base_completion/tests/test_base_completion.py 2014-03-04 13:23:57 +0000
26@@ -36,6 +36,8 @@
27 name_completion_case("A.one SA", "A.one SA for line", True),
28 name_completion_case("Acsone SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", False),
29 name_completion_case("Acsone ([^a-zA-Z0-9 -]) SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", True),
30+ name_completion_case(r"Acsone (.^$*+?()[{\| -]\) SA", r"Line for Acsone (.^$*+?()[{\| -]\) SA test", True),
31+ name_completion_case("Acšone SA", "Line for Acšone SA test", True),
32 ]
33
34

Subscribers

People subscribed via source and target branches