From ec9899e1df47d0dd04775cb5aa9a9caf1861ec77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gigandet?= Date: Thu, 20 Apr 2023 20:14:18 +0200 Subject: [PATCH 1/7] fix: escape issue in additives knowledge panel - remove latex formulas --- lib/ProductOpener/KnowledgePanels.pm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/ProductOpener/KnowledgePanels.pm b/lib/ProductOpener/KnowledgePanels.pm index 5c64b5f7fcbcd..c441640df762d 100644 --- a/lib/ProductOpener/KnowledgePanels.pm +++ b/lib/ProductOpener/KnowledgePanels.pm @@ -221,6 +221,8 @@ sub convert_multiline_string_to_singleline ($line) { # Escape quotes unless they have been escaped already # negative look behind to not convert \" to \\" $line =~ s/(?{$property} = $property_value; + $object_ref->{$property} = remove_latex_sequences($property_value); $object_ref->{$property . "_lc"} = $property_lc; $object_ref->{$property . "_language"} = display_taxonomy_tag($target_lcs_ref->[0], "languages", $language_codes{$property_lc}); From 84e281b93645a7b4b3daf73f96c78d78cdce8c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gigandet?= Date: Fri, 21 Apr 2023 09:02:07 +0200 Subject: [PATCH 2/7] fix escaping --- lib/ProductOpener/KnowledgePanels.pm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/ProductOpener/KnowledgePanels.pm b/lib/ProductOpener/KnowledgePanels.pm index c441640df762d..5558ded9d7127 100644 --- a/lib/ProductOpener/KnowledgePanels.pm +++ b/lib/ProductOpener/KnowledgePanels.pm @@ -218,11 +218,9 @@ sub convert_multiline_string_to_singleline ($line) { # \R will match all Unicode newline sequence $line =~ s/\R/\\n/sg; - # Escape quotes unless they have been escaped already - # negative look behind to not convert \" to \\" - $line =~ s/(? Date: Fri, 21 Apr 2023 13:42:41 +0200 Subject: [PATCH 3/7] do not double escape \n --- lib/ProductOpener/KnowledgePanels.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ProductOpener/KnowledgePanels.pm b/lib/ProductOpener/KnowledgePanels.pm index 5558ded9d7127..e4e4ff15ebf5c 100644 --- a/lib/ProductOpener/KnowledgePanels.pm +++ b/lib/ProductOpener/KnowledgePanels.pm @@ -219,8 +219,8 @@ sub convert_multiline_string_to_singleline ($line) { # \R will match all Unicode newline sequence $line =~ s/\R/\\n/sg; # Escape " and \ unless they have been escaped already - # negative look behind to not convert \" to \\" or \\ to \\\\ - $line =~ s/(? Date: Fri, 21 Apr 2023 14:55:19 +0200 Subject: [PATCH 4/7] do not double escape \n --- lib/ProductOpener/KnowledgePanels.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ProductOpener/KnowledgePanels.pm b/lib/ProductOpener/KnowledgePanels.pm index e4e4ff15ebf5c..c3b80ff28cd90 100644 --- a/lib/ProductOpener/KnowledgePanels.pm +++ b/lib/ProductOpener/KnowledgePanels.pm @@ -216,11 +216,13 @@ The function converts the multiline string into a single line string. sub convert_multiline_string_to_singleline ($line) { - # \R will match all Unicode newline sequence - $line =~ s/\R/\\n/sg; # Escape " and \ unless they have been escaped already # negative look behind to not convert \n to \\n or \" to \\" or \\ to \\\\ - $line =~ s/(? Date: Thu, 4 May 2023 10:52:34 +0200 Subject: [PATCH 5/7] remove unneeded escapes now handled in convert_multiline_string_to_singleline --- .../environment/carbon_footprint.tt.json | 2 +- .../environment/ecoscore/agribalyse.tt.json | 2 +- tests/unit/knowledge_panels.t | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/unit/knowledge_panels.t diff --git a/templates/api/knowledge-panels/environment/carbon_footprint.tt.json b/templates/api/knowledge-panels/environment/carbon_footprint.tt.json index e49b9a8e4f14a..43c0b308d834e 100644 --- a/templates/api/knowledge-panels/environment/carbon_footprint.tt.json +++ b/templates/api/knowledge-panels/environment/carbon_footprint.tt.json @@ -29,7 +29,7 @@ "type": "summary", "html": `

[% lang('source_ademe_agribalyse_for_category') %] - [% panel.agribalyse_category_name.dquote %] + [% panel.agribalyse_category_name.dquote %] ([% lang('source_ademe_agribalyse') %])

` diff --git a/templates/api/knowledge-panels/environment/ecoscore/agribalyse.tt.json b/templates/api/knowledge-panels/environment/ecoscore/agribalyse.tt.json index da0fd37150d38..d64541ade95b6 100644 --- a/templates/api/knowledge-panels/environment/ecoscore/agribalyse.tt.json +++ b/templates/api/knowledge-panels/environment/ecoscore/agribalyse.tt.json @@ -16,7 +16,7 @@ "type": "summary", "html": `

[% lang('categories_s') FILTER ucfirst %][% sep %]: - [% panel.agribalyse_category_name %] + [% panel.agribalyse_category_name %]