From ae259a6ef8dd3a8b209c1c866ee90bf73056181e Mon Sep 17 00:00:00 2001 From: haszi Date: Mon, 26 Feb 2024 18:16:21 +0100 Subject: [PATCH 1/2] Fix GH-98 Store IDs of non-chunked elements. Closes #98. --- phpdotnet/phd/Index.php | 3 +++ phpdotnet/phd/TestIndex.php | 8 ++++++++ tests/index/bug_GH-98.phpt | 37 ++++++++++++++++++++++++++++++++++ tests/index/data/bug_GH-98.xml | 28 +++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 phpdotnet/phd/TestIndex.php create mode 100644 tests/index/bug_GH-98.phpt create mode 100644 tests/index/data/bug_GH-98.xml diff --git a/phpdotnet/phd/Index.php b/phpdotnet/phd/Index.php index e0d119d3..8f991313 100644 --- a/phpdotnet/phd/Index.php +++ b/phpdotnet/phd/Index.php @@ -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; } diff --git a/phpdotnet/phd/TestIndex.php b/phpdotnet/phd/TestIndex.php new file mode 100644 index 00000000..f33a9c87 --- /dev/null +++ b/phpdotnet/phd/TestIndex.php @@ -0,0 +1,8 @@ +indexes; + } +} diff --git a/tests/index/bug_GH-98.phpt b/tests/index/bug_GH-98.phpt new file mode 100644 index 00000000..ef93dead --- /dev/null +++ b/tests/index/bug_GH-98.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug GH-98 - Non-chunked section is not linked +--FILE-- + true, + "xml_file" => $xml_file, +]); + +$index = new TestIndex; +$render = new TestRender(new Reader, new Config, null, $index); + +$render->run(); + +$indexes = array_keys($index->getIndexes()); + +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) diff --git a/tests/index/data/bug_GH-98.xml b/tests/index/data/bug_GH-98.xml new file mode 100644 index 00000000..dd1dba21 --- /dev/null +++ b/tests/index/data/bug_GH-98.xml @@ -0,0 +1,28 @@ + + + + + + Content to ensure this elements is indexed + + + +
+ + Content to ensure this elements is indexed too + +
+ + + + Content to ensure this elements is indexed as well + + + +
+ + Content to ensure this elements is also indexed + +
+ +
From 3c88dcd14f65fcbf290ed3b190dce0704d095e38 Mon Sep 17 00:00:00 2001 From: haszi Date: Mon, 26 Feb 2024 20:30:18 +0100 Subject: [PATCH 2/2] Force index and use parsed indexes --- phpdotnet/phd/Index.php | 2 +- phpdotnet/phd/TestIndex.php | 4 ++-- tests/index/bug_GH-98.phpt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpdotnet/phd/Index.php b/phpdotnet/phd/Index.php index 8f991313..24be8ab6 100644 --- a/phpdotnet/phd/Index.php +++ b/phpdotnet/phd/Index.php @@ -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 = ""; diff --git a/phpdotnet/phd/TestIndex.php b/phpdotnet/phd/TestIndex.php index f33a9c87..d5586d19 100644 --- a/phpdotnet/phd/TestIndex.php +++ b/phpdotnet/phd/TestIndex.php @@ -2,7 +2,7 @@ namespace phpdotnet\phd; class TestIndex extends Index { - public function getIndexes(): array { - return $this->indexes; + public function getNfo(): array { + return $this->nfo; } } diff --git a/tests/index/bug_GH-98.phpt b/tests/index/bug_GH-98.phpt index ef93dead..dcc9e434 100644 --- a/tests/index/bug_GH-98.phpt +++ b/tests/index/bug_GH-98.phpt @@ -9,7 +9,7 @@ require_once __DIR__ . "/../setup.php"; $xml_file = __DIR__ . "/data/bug_GH-98.xml"; Config::init([ - "index" => true, + "force_index" => true, "xml_file" => $xml_file, ]); @@ -18,7 +18,7 @@ $render = new TestRender(new Reader, new Config, null, $index); $render->run(); -$indexes = array_keys($index->getIndexes()); +$indexes = array_keys($index->getNfo()); echo "Indexes stored:\n";