From 83282f2deaa99f208911c26a919a4a00f9516e61 Mon Sep 17 00:00:00 2001 From: Mohammad Alhashash Date: Wed, 25 Mar 2015 10:54:16 +0200 Subject: [PATCH] [FIX] models: Escape `%` characters from error messages of a failed import To prevent susbtituion exception when creating use error message e.g. No matching record found for external id 'fo%o' in field 'Bar' Fixes #5933 --- openerp/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openerp/models.py b/openerp/models.py index c72bdd1a0ea..83a212096ac 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -1199,8 +1199,11 @@ class BaseModel(object): type = 'warning' if isinstance(exception, Warning) else 'error' # logs the logical (not human-readable) field name for automated # processing of response, but injects human readable in message - record = dict(base, type=type, field=field, - message=unicode(exception.args[0]) % base) + # Before applying string substitution, we need to escape all '%' + # characters that are not part of substitutable reference. + regex = '%%(?!\((%s)\)s)' % '|'.join(base.keys()) + message = unicode(re.sub(regex, '%%', exception.args[0])) % base + record = dict(base, type=type, field=field, message=message) if len(exception.args) > 1 and exception.args[1]: record.update(exception.args[1]) log(record)