Skip to content

Commit fcc475c

Browse files
committed
Keep version strings like "0.10" intact when loading guides.xml
guides.xml is parsed with Symfony XmlUtils::convertDomElementToArray(), which runs phpize() on every attribute value, coercing numeric-looking strings to numbers. A <project version="0.10"> therefore became the float 0.1 ("1.0" -> 1, "1.10" -> 1.1, "13.0" -> 13), so the project version and release rendered as "0.1" everywhere -- breaking version switchers and deployments that distinguish 0.1 from 0.10. The <project> attributes (title, version, release, copyright) are all strings, so restore them verbatim from the DOM after the array conversion. Reported on docs.typo3.org for netresearch/nr-vault and nr-llm (0.10 / 0.12). Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
1 parent 6d70127 commit fcc475c

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

packages/guides-cli/src/Config/XmlFileLoader.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace phpDocumentor\Guides\Cli\Config;
1515

16+
use DOMAttr;
17+
use DOMElement;
1618
use Symfony\Component\Config\Loader\FileLoader;
1719
use Symfony\Component\Config\Util\Exception\XmlParsingException;
1820
use Symfony\Component\Config\Util\XmlUtils;
@@ -39,6 +41,22 @@ public function load(mixed $resource, string|null $type = null): array
3941
$rootConfig = XmlUtils::convertDomElementToArray($element);
4042
assert(is_array($rootConfig));
4143

44+
// XmlUtils::convertDomElementToArray() runs phpize() on every attribute
45+
// value, which turns version-like strings into numbers: "0.10" becomes
46+
// the float 0.1, "1.0" becomes 1. The <project> attributes (title,
47+
// version, release, copyright) are all strings, so restore them verbatim
48+
// from the DOM to keep their exact value.
49+
$project = $element->getElementsByTagName('project')->item(0);
50+
if ($project instanceof DOMElement && isset($rootConfig['project']) && is_array($rootConfig['project'])) {
51+
foreach ($project->attributes as $attribute) {
52+
if (!$attribute instanceof DOMAttr) {
53+
continue;
54+
}
55+
56+
$rootConfig['project'][$attribute->name] = $attribute->value;
57+
}
58+
}
59+
4260
$configs = [];
4361
if (isset($rootConfig['import'])) {
4462
foreach ((array) $rootConfig['import'] as $import) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Versions - Example</title>
5+
6+
</head>
7+
<body>
8+
<!-- content start -->
9+
<div class="section" id="versions">
10+
<h1>Versions</h1>
11+
12+
<p>This documents version 0.10 (release 1.0).</p>
13+
14+
</div>
15+
<!-- content end -->
16+
</body>
17+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<guides xmlns="https://www.phpdoc.org/guides">
3+
<project title="Example" version="0.10" release="1.0"/>
4+
</guides>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
========
2+
Versions
3+
========
4+
5+
This documents version |version| (release |release|).

0 commit comments

Comments
 (0)