Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix element map so changelog rows are handled correctly #146

Merged
merged 7 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions phpdotnet/phd/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class Index extends Format
'titleabbrev' => 'format_short_desc',
'example' => 'format_example',
'refsect1' => 'format_refsect1',
'tbody' => array(
'row' => array(
/* DEFAULT */ null,
'row' => 'format_row',
'tbody' => 'format_row',
),
'entry' => array(
/* DEFAULT */ null,
Expand Down Expand Up @@ -98,7 +98,7 @@ class Index extends Format
private $inChangelog = false;
private $currentChangelog = array();
private string $currentChangeLogString = "";
private $changelog = array();
protected $changelog = array();
private $currentMembership = null;
private $commit = array();
private $POST_REPLACEMENT_INDEXES = array();
Expand Down Expand Up @@ -419,17 +419,19 @@ public function format_entry($open, $name, $attrs, $props) {
$this->currentChangelog[] = htmlentities(trim($this->currentChangeLogString), ENT_COMPAT, "UTF-8");
}
}

public function format_row($open, $name, $attrs, $props) {
if ($open) {
if ($this->inChangelog) {
end($this->ids); prev($this->ids);
$this->currentChangelog = array($this->currentMembership, current($this->ids));
}
return;
}
if ($this->inChangelog) {
$this->changelog[$this->currentid][] = $this->currentChangelog;
if ($open) {
$parent_id = $this->ids[count($this->ids) - 2];
$this->currentChangelog = array($this->currentMembership, $parent_id);
} else {
$this->changelog[$this->currentid][] = $this->currentChangelog;
}
}

/* Fall back to regular handling so contents get processed */
return $this->UNDEF($open, $name, $attrs, $props);
}

public function processFilename() {
Expand Down
18 changes: 10 additions & 8 deletions phpdotnet/phd/IndexRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ private function saveChangelogs(array $changelog): void {
$log = "";
foreach($changelog as $id => $arr) {
foreach($arr as $entry) {
$log .= sprintf(
"INSERT INTO changelogs (membership, docbook_id, parent_id, version, description) VALUES('%s', '%s', '%s', '%s', '%s');\n",
$this->db->escapeString($entry[0] ?? ''),
$this->db->escapeString($id),
$this->db->escapeString($entry[1]),
$this->db->escapeString($entry[2]),
$this->db->escapeString($entry[3])
);
foreach(preg_split('/,\s+/', $entry[2]) as $version) {
$log .= sprintf(
"INSERT INTO changelogs (membership, docbook_id, parent_id, version, description) VALUES('%s', '%s', '%s', '%s', '%s');\n",
$this->db->escapeString($entry[0] ?? ''),
$this->db->escapeString($id),
$this->db->escapeString($entry[1]),
$this->db->escapeString($version),
$this->db->escapeString($entry[3])
);
}
}
}
$this->db->exec('BEGIN TRANSACTION; ' . $log. ' COMMIT');
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/PI/PHPDOCHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function parse($target, $data) {
// usort() callback function used in generate-changelog-for, higest (newest) version first
// 1.2.11 comes before 1.2.2, then function name (actually its id.. but close enough :))
protected static function _sortByVersion($a, $b) {
$retval = -1 * strnatcasecmp($a["version"], $b["version"]);
$retval = -1 * version_compare($a["version"], $b["version"]);

if ($retval === 0) {
return strnatcasecmp($a["docbook_id"], $b["docbook_id"]);
Expand All @@ -138,7 +138,7 @@ protected function generateChangelogMarkup($changelogs) {

$version = "";
foreach($changelogs as $entry) {
if (!$this->_changelogSince || strnatcasecmp($entry["version"], $this->_changelogSince) >= 0) {
if (!$this->_changelogSince || version_compare($entry["version"], $this->_changelogSince) >= 0) {
$link = $this->format->createLink($entry["docbook_id"], $desc);
if ($version == $entry["version"]) {
$v = " ";
Expand Down
4 changes: 4 additions & 0 deletions phpdotnet/phd/TestIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ class TestIndex extends Index {
public function getNfo(): array {
return $this->nfo;
}

public function getChangelog(): array {
return $this->changelog;
}
}
65 changes: 65 additions & 0 deletions tests/bug_GH-87.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
--TEST--
GH-87 Broken links for constants in table rows
--FILE--
<?php
namespace phpdotnet\phd;

require_once __DIR__ . "/setup.php";

$xml_file = __DIR__ . "/data/bug_GH-87.xml";

$config->setForce_index(true);
$config->setXml_file($xml_file);

$indexRepository = new IndexRepository(new \SQLite3(":memory:"));
$indexRepository->init();
$config->set_indexcache($indexRepository);

$index = new TestIndex($indexRepository, $config);

$render = new TestRender(new Reader, $config, null, $index);

$render->run();

$render = new TestRender(new Reader, $config);

$format = new TestGenericChunkedXHTML($config);

$render->attach($format);

$render->run();

?>
--EXPECT--
Filename: constants.html
Content:
<div id="constants" class="chapter">
<div class="section">
<p class="para">Constant within a table (GH-87)</p>
<p class="para">
<table class="doctable informaltable">

<thead>
<tr>
<th>Header</th>
</tr>

</thead>

<tbody class="tbody">
<tr id="constant.defined">
<td><strong><code>CONSTANT_IS_DEFINED</code></strong></td>
</tr>

</tbody>

</table>

</p>
</div>
<div class="section">
<p class="para">
<a href="constants.html#constant.defined" class="link">CONSTANT_IS_DEFINED</a>
</p>
</div>
</div>
27 changes: 27 additions & 0 deletions tests/data/bug_GH-87.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<chapter xml:id="constants">
<section>
<para>Constant within a table (GH-87)</para>
<para>
<informaltable>
<tgroup cols="1">
<thead>
<row>
<entry>Header</entry>
</row>
</thead>
<tbody>
<row xml:id="constant.defined">
<entry><constant>CONSTANT_IS_DEFINED</constant></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</section>
<section>
<para>
<link linkend="constant.defined">CONSTANT_IS_DEFINED</link>
</para>
</section>
</chapter>
25 changes: 22 additions & 3 deletions tests/index/data/indexing_001.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,31 @@
<title>The <interfacename>Traversable</interfacename> interface</title>
<titleabbrev>Traversable</titleabbrev>
<partintro>
<section role="changelog">
<refsect1 role="changelog">
<title xmlns="http://docbook.org/ns/docbook">Changelog</title>
<para>
Changes
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Version</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>7.3.4, 8.0.0</entry>
<entry>Something happened.</entry>
</row>
<row>
<entry>PECL example 3.5.4</entry>
<entry>Something happened in PECL.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</section>
</refsect1>
</partintro>
</phpdoc:classref>

Expand Down
11 changes: 11 additions & 0 deletions tests/index/indexing_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ $indexes = array_keys($index->getNfo());
echo "Indexes stored:\n";

var_dump($indexes);

$changelog = array_keys($index->getChangelog());

echo "Changelog stored:\n";

var_dump($changelog);
?>
--EXPECT--
Indexes stored:
Expand Down Expand Up @@ -59,3 +65,8 @@ array(15) {
[14]=>
string(17) "class.traversable"
}
Changelog stored:
array(1) {
[0]=>
string(17) "class.traversable"
}
Loading