Skip to content

Commit 017d4a7

Browse files
authored
[BUGFIX] DOMDocument escapes arrows (#297)
Resolves: #259
1 parent 3690ffe commit 017d4a7

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ indent_style = tab
1717
indent_size = 2
1818

1919
# XML-Files
20-
[*.xml]
20+
[{*.xml,*.xml.fixture}]
2121
indent_style = tab
2222
indent_size = 4

packages/fractor-xml/src/XmlFileProcessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function handle(File $file, iterable $appliedRules): void
5555
$iterator->traverseDocument($file, $document);
5656

5757
$newXml = $this->saveXml($document);
58+
$newXml = str_replace('->', '->', $newXml);
5859
$newXml = $this->formatter->format($this->indent, $newXml) . "\n";
5960

6061
if ($newXml === $originalXml) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace a9f\FractorXml\Tests\Fixtures;
6+
7+
use a9f\Typo3Fractor\AbstractFlexformFractor;
8+
use a9f\Typo3Fractor\Helper\FlexFormHelperTrait;
9+
use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
10+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
11+
12+
final class DummyXmlFractorRule extends AbstractFlexformFractor
13+
{
14+
use FlexFormHelperTrait;
15+
16+
public function canHandle(\DOMNode $node): bool
17+
{
18+
return parent::canHandle($node) && $node->nodeName === 'config';
19+
}
20+
21+
public function refactor(\DOMNode $node): \DOMNode|null
22+
{
23+
if (! $node instanceof \DOMElement) {
24+
return null;
25+
}
26+
$this->removeChildElementFromDomElementByKey($node, 'max');
27+
return $node;
28+
}
29+
30+
public function getRuleDefinition(): RuleDefinition
31+
{
32+
throw new BadMethodCallException('Not implemented yet');
33+
}
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<T3DataStructure>
3+
<sheets>
4+
<sDEF>
5+
<ROOT>
6+
<el>
7+
<settings.input>
8+
<config>
9+
<type>input</type>
10+
<numIndex>Person->showSelected</numIndex>
11+
<max>50</max>
12+
</config>
13+
</settings.input>
14+
</el>
15+
</ROOT>
16+
</sDEF>
17+
</sheets>
18+
</T3DataStructure>
19+
-----
20+
<?xml version="1.0" encoding="UTF-8"?>
21+
<T3DataStructure>
22+
<sheets>
23+
<sDEF>
24+
<ROOT>
25+
<el>
26+
<settings.input>
27+
<config>
28+
<type>input</type>
29+
<numIndex>Person->showSelected</numIndex>
30+
</config>
31+
</settings.input>
32+
</el>
33+
</ROOT>
34+
</sDEF>
35+
</sheets>
36+
</T3DataStructure>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace a9f\FractorXml\Tests\XmlFileProcessor;
6+
7+
use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase;
8+
use a9f\FractorXml\Tests\Fixtures\DummyXmlFractorRule;
9+
use PHPUnit\Framework\Attributes\DataProvider;
10+
11+
final class XmlFileProcessorTest extends AbstractFractorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
$this->assertThatRuleIsApplied(DummyXmlFractorRule::class);
18+
}
19+
20+
public static function provideData(): \Iterator
21+
{
22+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixtures', '*.xml.fixture');
23+
}
24+
25+
public function provideConfigFilePath(): string
26+
{
27+
return __DIR__ . '/config/fractor.php';
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use a9f\Fractor\Configuration\FractorConfiguration;
6+
use a9f\Fractor\ValueObject\Indent;
7+
use a9f\FractorXml\Configuration\XmlProcessorOption;
8+
use a9f\FractorXml\Tests\Fixtures\DummyXmlFractorRule;
9+
10+
return FractorConfiguration::configure()
11+
->withOptions([
12+
XmlProcessorOption::INDENT_CHARACTER => Indent::STYLE_TAB,
13+
XmlProcessorOption::INDENT_SIZE => 1,
14+
])
15+
->withRules([DummyXmlFractorRule::class]);

0 commit comments

Comments
 (0)