mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-07 17:06:54 +01:00
chore: Refactor XML text encoding
Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
@@ -77,18 +77,18 @@ final class XmlCategoryExport extends Service implements XmlCategoryExportServic
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$nodeCategory = $document->createElement('Category');
|
||||
$nodeCategories->appendChild($nodeCategory);
|
||||
|
||||
$nodeCategory->setAttribute('id', $category->getId());
|
||||
$nodeCategory->appendChild(
|
||||
$document->createElement('name', XmlUtil::escapeChars($category->getName()))
|
||||
$document->createElement('name', $document->createTextNode($category->getName())->nodeValue)
|
||||
);
|
||||
$nodeCategory->appendChild(
|
||||
$document->createElement(
|
||||
'description',
|
||||
XmlUtil::escapeChars($category->getDescription())
|
||||
$document->createTextNode($category->getDescription())->nodeValue
|
||||
)
|
||||
);
|
||||
|
||||
$nodeCategories->appendChild($nodeCategory);
|
||||
}
|
||||
|
||||
return $nodeCategories;
|
||||
|
||||
@@ -78,13 +78,18 @@ final class XmlClientExport extends Service implements XmlClientExportService
|
||||
|
||||
foreach ($clients as $client) {
|
||||
$nodeClient = $document->createElement('Client');
|
||||
$nodeClient->setAttribute('id', $client->getId());
|
||||
$nodeClient->appendChild($document->createElement('name', XmlUtil::escapeChars($client->getName())));
|
||||
$nodeClient->appendChild(
|
||||
$document->createElement('description', XmlUtil::escapeChars($client->getDescription()))
|
||||
);
|
||||
|
||||
$nodeClients->appendChild($nodeClient);
|
||||
|
||||
$nodeClient->setAttribute('id', $client->getId());
|
||||
$nodeClient->appendChild(
|
||||
$document->createElement('name', $document->createTextNode($client->getName())->nodeValue)
|
||||
);
|
||||
$nodeClient->appendChild(
|
||||
$document->createElement(
|
||||
'description',
|
||||
$document->createTextNode($client->getDescription())->nodeValue
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $nodeClients;
|
||||
|
||||
@@ -32,7 +32,6 @@ use SP\Core\Events\Event;
|
||||
use SP\Core\Events\EventMessage;
|
||||
use SP\Domain\Common\Services\Service;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Export\Services\XmlUtil;
|
||||
use SP\Domain\Tag\Services\TagService;
|
||||
|
||||
use function SP\__u;
|
||||
@@ -43,7 +42,7 @@ use function SP\__u;
|
||||
final class XmlTagExport extends Service implements XmlTagExportService
|
||||
{
|
||||
public function __construct(
|
||||
Application $application,
|
||||
Application $application,
|
||||
private readonly TagService $tagService,
|
||||
|
||||
) {
|
||||
@@ -77,10 +76,12 @@ final class XmlTagExport extends Service implements XmlTagExportService
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
$nodeTag = $document->createElement('Tag');
|
||||
$nodeTag->setAttribute('id', $tag->getId());
|
||||
$nodeTag->appendChild($document->createElement('name', XmlUtil::escapeChars($tag->getName())));
|
||||
|
||||
$nodeTags->appendChild($nodeTag);
|
||||
|
||||
$nodeTag->setAttribute('id', $tag->getId());
|
||||
$nodeTag->appendChild(
|
||||
$document->createElement('name', $document->createTextNode($tag->getName())->nodeValue)
|
||||
);
|
||||
}
|
||||
|
||||
return $nodeTags;
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Domain\Export\Services;
|
||||
|
||||
/**
|
||||
* Class XmlUtil
|
||||
*/
|
||||
final class XmlUtil
|
||||
{
|
||||
/**
|
||||
* Escapar carácteres no válidos en XML
|
||||
*
|
||||
* @param $data string Los datos a escapar
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function escapeChars(string $data): string
|
||||
{
|
||||
$arrStrFrom = ['&', '<', '>', '"', '\''];
|
||||
$arrStrTo = ['&', '<', '>', '"', '''];
|
||||
|
||||
return str_replace($arrStrFrom, $arrStrTo, $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user