From cc54b7fe29f4ba2c47312f00643f89caf49b281d Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Thu, 25 Mar 2021 00:03:09 +0100
Subject: [PATCH] Fix dol_string_onlythesehtmlattributes
---
htdocs/categories/edit.php | 1 -
htdocs/core/lib/functions.lib.php | 9 ++++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php
index 176b39ca008..91d32736cbc 100644
--- a/htdocs/categories/edit.php
+++ b/htdocs/categories/edit.php
@@ -99,7 +99,6 @@ if ($action == 'update' && $user->rights->categorie->creer) {
$object->visible = $visible;
$object->fk_parent = $parent != -1 ? $parent : 0;
-
if (empty($object->label)) {
$error++;
$action = 'edit';
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 50ff91a6508..2d75d8ed90b 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -6335,6 +6335,8 @@ function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1,
function dol_string_onlythesehtmlattributes($stringtoclean, $allowed_attributes = array("alt", "class", "contenteditable", "data-html", "href", "id", "name", "src", "style", "target", "title"))
{
if (class_exists('DOMDocument') && !empty($stringtoclean)) {
+ $stringtoclean = ''.$stringtoclean.'';
+ var_dump($stringtoclean);
$dom = new DOMDocument();
$dom->loadHTML($stringtoclean, LIBXML_ERR_NONE|LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD|LIBXML_NONET|LIBXML_NOWARNING|LIBXML_NOXMLDECL);
if (is_object($dom)) {
@@ -6348,7 +6350,12 @@ function dol_string_onlythesehtmlattributes($stringtoclean, $allowed_attributes
}
}
- return $dom->saveHTML();
+ $return = $dom->saveHTML();
+
+ //$return = 'aaaa
bbssdd
'."\naaa
aabb
";
+ $return = preg_replace('/^/', '', $return);
+ $return = preg_replace('/<\/body><\/html>$/', '', $return);
+ return $return;
} else {
return $stringtoclean;
}