account_statement_base_completion: invalid regular expression: invalid escape \ sequence
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Banking Addons |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
When using the autocompletion with get_from_
Traceback (most recent call last):
File "/home/
res = self._obj.
DataError: invalid regular expression: invalid escape \ sequence
When it executes this query:
sql = """SELECT id FROM (
result = cr.fetchall()
The tests are green (and they cover this query) but they do not cover a corner case where the name contains special unicode chars.
The regexp_replace in the query escape the name, example:
"jovial (<email address hidden>)" is escaped as "jovial \(m.blanc\
The problem is that it escape too much characters, example:
openerp=# select regexp_
regexp_replace
----------------
Jérôme bla\š
Here the 'š' should not have been escaped, resulting in the "invalid regular expression: invalid escape \ sequence" error.
Related branches
- Laurent Mignon (Acsone) (community): Approve (code review, no tests)
- Sébastien BEAU - http://www.akretion.com: Approve (code review, no tests)
- Yannick Vaucher @ Camptocamp: Approve (code review, no tests)
-
Diff: 32 lines (+10/-2)2 files modifiedaccount_statement_base_completion/statement.py (+8/-2)
account_statement_base_completion/tests/test_base_completion.py (+2/-0)
description: | updated |
description: | updated |
Changed in banking-addons: | |
status: | New → Fix Released |
Using "\\\1" would be wrong as the query would be:
SELECT id FROM (
SELECT id, regexp_ matches( '00774000000000 0000020101806' , regexp_ replace( name,'( [^[:alpha: ]0-9 -])', '\', 'g'), 'i') AS name_match FROM res_partner
) AS res_patner_matcher
WHERE name_match IS NOT NULL
Instead of
SELECT id FROM (
SELECT id, regexp_ matches( '00774000000000 0000020101806' , regexp_ replace( name,'( [^[:alpha: ]0-9 -])', '\1', 'g'), 'i') AS name_match FROM res_partner
) AS res_patner_matcher
WHERE name_match IS NOT NULL
My feeling is that the correct query would be:
sql = """SELECT id FROM (
SELECT id, regexp_matches(%s, regexp_ replace( name,'( [^[:alpha: ]0-9 -])', E'\\1', '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'], context[ 'partner_ memoizer' ]))
result = cr.fetchall()
But a test do no longer pass and I can't figure out how it is supposed to work yet.