Skip to content

Commit

Permalink
Fix GH-3353 incorrect function tag linking
Browse files Browse the repository at this point in the history
  • Loading branch information
haszi committed May 20, 2024
1 parent fc84db4 commit c3759b9
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 9 deletions.
8 changes: 1 addition & 7 deletions phpdotnet/phd/IndexRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,7 @@ public function getRefNames(): array {


private function SQLiteRefname($context, $index, $id, $sdesc): void {
$ref = strtolower(
str_replace(
["_", "::", "->"],
["-", "-", "-"],
html_entity_decode($sdesc, ENT_QUOTES, 'UTF-8')
)
);
$ref = strtolower(html_entity_decode($sdesc, ENT_QUOTES, 'UTF-8'));
$this->refs[$ref] = $id;
}

Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/Generic/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public function format_function_text($value, $tag, $display_value = null) {
$display_value = $value;
}

$ref = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $value));
$ref = strtolower($value);
if (($linkend = $this->getRefnameLink($ref)) !== null) {
$this->pdfDoc->setFont(PdfWriter::FONT_NORMAL, 12, array(0, 0, 1)); // blue
$linkAreas = $this->pdfDoc->add(PdfWriter::LINK_ANNOTATION, $display_value.($tag == "function" ? "()" : ""));
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/PHP/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ public function format_function_text($value, $tag, $display_value = null) {
if (isset($non_functions[$value])) {
$filename = "function." . str_replace("_", "-", $value);
} else {
$ref = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $value));
$ref = strtolower($value);
$filename = $this->getRefnameLink($ref);
}
if ($filename !== null) {
Expand Down
101 changes: 101 additions & 0 deletions tests/bug_doc-en_GH-3353.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
--TEST--
Bug doc-en GH-3353 - incorrect method/function linking when a method's name and a function's name are normalized to the same string
--FILE--
<?php
namespace phpdotnet\phd;

require_once __DIR__ . "/setup.php";

$xml_file = __DIR__ . "/data/bug_doc-en_GH-3353.xml";

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

$render = new Render();

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


// Indexing
$index = new TestIndex($indexRepository);
$render->attach($index);

$reader = new Reader;
$reader->open(Config::xml_file(), null, LIBXML_PARSEHUGE | LIBXML_XINCLUDE);
$render->execute($reader);

$render->detach($index);


// Rendering
$format = new TestPHPChunkedXHTML;
$render->attach($format);

$reader = new Reader;
$reader->open(Config::xml_file(), null, LIBXML_PARSEHUGE | LIBXML_XINCLUDE);

$render->execute($reader);
?>
--EXPECT--
Filename: method.and.function.html
Content:
<div id="method.and.function" class="refentry">
<div class="refnamediv">
<h1 class="refname">ClassName::methodName</h1>
<h1 class="refname">classname_methodname</h1>
<p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">ClassName::methodName</span> -- <span class="refname">classname_methodname</span> &mdash; <span class="dc-title">1. This is the first method/function description</span></p>

</div>
<div class="refsect1 description" id="method.and.function-description">
<p class="para">
Link to <span class="function"><a href="method.only.html" class="function">ClassName::methodName()</a></span>
and to <span class="function"><a href="function.only.html" class="function">classname_methodname()</a></span>
</p>
</div>

</div>
Filename: method.only.html
Content:
<div id="method.only" class="refentry">
<div class="refnamediv">
<h1 class="refname">ClassName::methodName</h1>
<p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">ClassName::methodName</span> &mdash; <span class="dc-title">2. This is the second (method) description</span></p>

</div>
<div class="refsect1 description" id="method.only-description">
<p class="para">
Link to <span class="function"><strong>ClassName::methodName()</strong></span>
and to <span class="function"><a href="function.only.html" class="function">classname_methodname()</a></span>
</p>
</div>

</div>
Filename: function.only.html
Content:
<div id="function.only" class="refentry">
<div class="refnamediv">
<h1 class="refname">classname_methodname</h1>
<p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">classname_methodname</span> &mdash; <span class="dc-title">3. This is the third (function) description</span></p>

</div>
<div class="refsect1 description" id="function.only-description">
<p class="para">
Link to <span class="function"><a href="method.only.html" class="function">ClassName::methodName()</a></span>
and to <span class="function"><strong>classname_methodname()</strong></span>
</p>
</div>

</div>
Filename: function.only.html
Content:
<div id="bug_doc-en_GH-3353" class="refentry">





</div>
41 changes: 41 additions & 0 deletions tests/data/bug_doc-en_GH-3353.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<refentry xml:id="bug_doc-en_GH-3353">
<refentry xml:id="method.and.function">
<refnamediv>
<refname>ClassName::methodName</refname>
<refname>classname_methodname</refname>
<refpurpose>1. This is the first method/function description</refpurpose>
</refnamediv>
<refsect1 role="description" xml:id="method.and.function-description">
<para>
Link to <function>ClassName::methodName</function>
and to <function>classname_methodname</function>
</para>
</refsect1>
</refentry>

<refentry xml:id="method.only">
<refnamediv>
<refname>ClassName::methodName</refname>
<refpurpose>2. This is the second (method) description</refpurpose>
</refnamediv>
<refsect1 role="description" xml:id="method.only-description">
<para>
Link to <function>ClassName::methodName</function>
and to <function>classname_methodname</function>
</para>
</refsect1>
</refentry>

<refentry xml:id="function.only">
<refnamediv>
<refname>classname_methodname</refname>
<refpurpose>3. This is the third (function) description</refpurpose>
</refnamediv>
<refsect1 role="description" xml:id="function.only-description">
<para>
Link to <function>ClassName::methodName</function>
and to <function>classname_methodname</function>
</para>
</refsect1>
</refentry>
</refentry>

0 comments on commit c3759b9

Please sign in to comment.