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 GH-98 #105

Merged
merged 2 commits into from
Feb 27, 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
5 changes: 4 additions & 1 deletion phpdotnet/phd/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Index extends Format
private $currentid;
private $chunks = array();
private $isChunk = array();
private $nfo = array();
protected $nfo = array();
private $isSectionChunk = array();
private $log = '';
private $previousId = "";
Expand Down Expand Up @@ -383,6 +383,9 @@ public function format_chunk($open, $name, $attrs, $props) {
$this->chunks[] = $id;
$this->currentchunk = $id;
$this->storeInfo($name, $id, $id);
} else {
$this->storeInfo($name, $id, $this->currentchunk, false);
$this->appendID();
}
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions phpdotnet/phd/TestIndex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace phpdotnet\phd;

class TestIndex extends Index {
public function getNfo(): array {
return $this->nfo;
}
}
37 changes: 37 additions & 0 deletions tests/index/bug_GH-98.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
Bug GH-98 - Non-chunked section is not linked
--FILE--
<?php
namespace phpdotnet\phd;

require_once __DIR__ . "/../setup.php";

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

Config::init([
"force_index" => true,
"xml_file" => $xml_file,
]);

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

$render->run();

$indexes = array_keys($index->getNfo());

echo "Indexes stored:\n";

var_dump(in_array("non-chunked.element.id", $indexes));
var_dump(in_array("another.non-chunked.element.id", $indexes));
var_dump(in_array("chunked.element.id", $indexes));
var_dump(in_array("another.chunked.element.id", $indexes));
var_dump(in_array("bug-GH-98", $indexes));
?>
--EXPECT--
Indexes stored:
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
28 changes: 28 additions & 0 deletions tests/index/data/bug_GH-98.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<chapter xml:id="bug-GH-98">

<sect1 xmlns="http://docbook.org/ns/docbook" annotations="chunk:false" xml:id="non-chunked.element.id">
<para>
Content to ensure this elements is indexed
</para>
</sect1>

<section xmlns="http://docbook.org/ns/docbook" annotations="chunk:false" xml:id="another.non-chunked.element.id">
<para>
Content to ensure this elements is indexed too
</para>
</section>

<sect1 xmlns="http://docbook.org/ns/docbook" xml:id="chunked.element.id">
<para>
Content to ensure this elements is indexed as well
</para>
</sect1>

<section xmlns="http://docbook.org/ns/docbook" xml:id="another.chunked.element.id">
<para>
Content to ensure this elements is also indexed
</para>
</section>

</chapter>
Loading