From 84f0d0ff40fe37b812e5aa748b3289e90cbaae7d Mon Sep 17 00:00:00 2001 From: diagnoza Date: Thu, 24 Oct 2024 16:26:56 +0000 Subject: [PATCH] [IMP] util/fields: update default when converting to html One could use Python escape sequences in text fields. When converting a field to HTML, they will no longer work, so replace them with HTML tags. --- src/util/fields.py | 15 +++++++++++++++ src/util/pg.py | 19 +++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/util/fields.py b/src/util/fields.py index 3a50bbd0..58065c69 100644 --- a/src/util/fields.py +++ b/src/util/fields.py @@ -654,6 +654,21 @@ def convert_field_to_html(cr, model, field, skip_inherit=()): """, [field, model], ) + + # Update ir.default + if table_exists(cr, "ir_default"): + json_value_html = pg_text2html("json_value") + cr.execute( + """ + UPDATE ir_default AS d + SET json_value = {} + FROM ir_model_fields AS imf + WHERE imf.name = %s + AND imf.model = %s + AND imf.id = d.field_id + """.format(json_value_html), + [field, model], + ) for inh in for_each_inherit(cr, model, skip_inherit): convert_field_to_html(cr, inh.model, field, skip_inherit=skip_inherit) diff --git a/src/util/pg.py b/src/util/pg.py index ea84abab..e3282b50 100644 --- a/src/util/pg.py +++ b/src/util/pg.py @@ -390,14 +390,17 @@ def pg_text2html(s, wrap="p"): CASE WHEN TRIM(COALESCE({src}, '')) ~ '^<.+$' THEN {src} ELSE CONCAT( '{opening_tag}', - replace(REGEXP_REPLACE({esc}, - -- regex from https://blog.codinghorror.com/the-problem-with-urls/ - -- double the %% to allow this code chunk to be used in parameterized queries - 'https?://[-A-Za-z0-9+&@#/%%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%%=~_()|]', - '\&', - 'g'), - E'\n', - '
'), + replace( + replace(REGEXP_REPLACE({esc}, + -- regex from https://blog.codinghorror.com/the-problem-with-urls/ + -- double the %% to allow this code chunk to be used in parameterized queries + 'https?://[-A-Za-z0-9+&@#/%%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%%=~_()|]', + '\&', + 'g'), + E'\\n', + '
'), + E'\\t', + ' '), '{closing_tag}') END """.format(