From 7f8631a913de7aebb9b9543309711812bfa5934b Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 2 Jan 2019 13:55:07 +0000 Subject: [PATCH] [FIX] tools: properly verify the size of HTML nodes Instead of checking the size of text only node, let the xml_translate verify it. The size verification using etree was introduced at 40efdccc3d1e1f070c9 but was probably too simple. Since 45352512a842, this becomes redundant with the nonspace method which can be extended. The re.sub is still relevant as some terms may contain only non-alphanumeric and use push_translation (e.g. '>=' as a selection or xml terms extracted by babel in static repository) closes odoo/odoo#29432 --- odoo/tools/translate.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 3c031f3d277..5561aa082c7 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -159,7 +159,7 @@ def translate_xml_node(node, callback, parse, serialize): """ def nonspace(text): - return bool(text) and not text.isspace() + return bool(text) and len(re.sub(r'\W+', '', text)) > 1 def concat(text1, text2): return text2 if text1 is None else text1 + (text2 or "") @@ -810,14 +810,6 @@ def trans_generate(lang, modules, cr): # empty and one-letter terms are ignored, they probably are not meant to be # translated, and would be very hard to translate anyway. sanitized_term = (source or '').strip() - try: - # verify the minimal size without eventual xml tags - # wrap to make sure html content like 'bd' is accepted by lxml - wrapped = u"
%s
" % sanitized_term - node = etree.fromstring(wrapped) - sanitized_term = etree.tostring(node, encoding='unicode', method='text') - except etree.ParseError: - pass # remove non-alphanumeric chars sanitized_term = re.sub(r'\W+', '', sanitized_term) if not sanitized_term or len(sanitized_term) <= 1: