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

A tag without href causes error in Rels #1562

Open
10types opened this issue Jan 28, 2019 · 2 comments · May be fixed by #2280
Open

A tag without href causes error in Rels #1562

10types opened this issue Jan 28, 2019 · 2 comments · May be fixed by #2280
Assignees

Comments

@10types
Copy link

10types commented Jan 28, 2019

The following causes an error "Invalid parameters passed" in Rels

HTMLParser::addHtml($section,'<a title="Link to Foo">Foo</a>',false);

The link above is nonsense logically (no href and no name makes it pointless in HTML) but it's still valid HTML. The lack of href causes an exception rather than (for example) rendering it as unlinked text.

@troosan troosan self-assigned this Jan 30, 2019
@branchard
Copy link

The following code also causes an error:
HTMLParser::addHtml($section,'<a href="#">Foo</a>',false);

@santerref
Copy link

Here is a patch I am using to make this working:

diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php
index 4e8dc17..0633f47 100644
--- a/src/PhpWord/Shared/Html.php
+++ b/src/PhpWord/Shared/Html.php
@@ -813,7 +813,11 @@ class Html
         }
         $styles['font'] = self::parseInlineStyle($node, $styles['font']);
 
-        if (strpos($target, '#') === 0) {
+        if(empty($target)) {
+          $target = '#';
+        }
+
+        if (strpos($target, '#') === 0 && strlen($target) > 1) {
             return $element->addLink(substr($target, 1), $node->textContent, $styles['font'], $styles['paragraph'], true);
         }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants