Skip to content

AddHTML & or & breaks #514

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

Closed
klompenrunner opened this issue Mar 29, 2015 · 10 comments
Closed

AddHTML & or & breaks #514

klompenrunner opened this issue Mar 29, 2015 · 10 comments

Comments

@klompenrunner
Copy link

Taken from: Sample_26_Html.php

The sample works:
'<p>Some well formed HTML snippet needs to be used<p>';

Bad HTML like this as expected breaks the XML:
'<p>Some well formed HTML snippet needs & to be used<p>';

When I add an HTML ampersand it breaks the XML too:
'<p>Some well formed HTML snippet needs &amp; to be used<p>';

But double escaping the ampersand makes it work.
'<p>Some well formed HTML snippet needs &amp;amp; to be used<p>';

Tested with -master and -developer today.

@gmta
Copy link
Contributor

gmta commented May 21, 2015

Of course, when the API works like every other API out there in the world, the following snippet should be the one to work:

'<p>Some well formed HTML snippet needs &amp; to be used<p>';

@chrispen
Copy link

chrispen commented Jul 6, 2015

Hi
I did the following:
I wrote an html header containing &

But i am getting illegal chars error message. However, it works when i double escape it.
I am new to phpword. May someone brief me why this is not working as expected.
Thank you.
chris

@chrispen
Copy link

chrispen commented Jul 8, 2015

Hi
I made the following changes to addHtml(), line 51-52, double escaping & and &amp.
@klompenrunner ; And it's now working.
Thank you
chrispen

@anrikun
Copy link
Contributor

anrikun commented Oct 2, 2015

Same issue here.
Any HTML containing entity &amp; added through addHtml() breaks document.xml.

@dzafel
Copy link

dzafel commented Jan 7, 2016

+1
$amp; does not work, breaks document.xml BUT also & does not work, breaks document.xml as well. What the hell?

@dzafel
Copy link

dzafel commented Jan 7, 2016

I think I found the issue, it's because authors of PHPWord use DOMDocument::loadXML in \PhpOffice\PhpWord\Shared\Html class. It replaces &amp; back to &, and then it's added to Word document, that's obviously an error in XML file, please replace entities with something like ~amp~ before loadXML and then replace them back to &amp; when you get the raw text using ->nodeValue, right now you're doing it all before loadXML which is wrong. I can't find any workaround other than just creating a fixed clone of Html class and use it instead of the original one.

@gmta
Copy link
Contributor

gmta commented Jan 11, 2016

@dzafel The author thinks you should apply escaping yourself, even if that is impossible, such as in your case. Please see issue #401 for a depressing discussion I had with @RomanSyroeshko about why he thinks PHPWord should work differently from every other library ever developed.

You'll probably be better off forking this repository and making the necessary changes yourself.

@dzafel
Copy link

dzafel commented Jan 11, 2016

@gmta yeah, I saw that thread. Unfortunatelly I don't have any time to wait for a fix, I made a dirty-fix for now - I cloned Html class, but I also found pandoc software and I think I'm going to switch to it, PHPWord is way too unstable, even if they "consider introducing escaping components in the next release"...

@ghost
Copy link

ghost commented Jan 11, 2016

To those who prefer to argue and to complain instead of doing something with his hands making thus the world better.

a) If you're brave, smart and experienced enough to define how a good open-source library should evolve, prove that and ask to be a part of the team. Many teams will be glad to have such professional. As for the PHPWord. As you can see by commit history, it experiences great lack of professional care. It needs you! So, you can try right here, right now.

b) If you're maverick and working with existing team is not and option for you, you can always maintain a fork. God bless GitHub, because it allows us to do that in a few steps!

c) If you're disappointed by people who maintain a library and don't like its codebase too, there is another option. Build your own next-gen library using all best practices, cutting-edge technologies and standards. I think this is the best option, because in a couple days with a few lines of code you can build a library which really rocks.

If you're not following a), not following b) and not following c), all of your words are just "blah-blah blah-blah blah". Please, stop wasting other peoples' time. Believe or not, but that makes the world better too.

Thanks. Nothing personal.

@ghost ghost locked and limited conversation to collaborators Jan 11, 2016
@ghost ghost locked and limited conversation to collaborators Jan 11, 2016
@ghost ghost self-assigned this Jun 29, 2016
@ghost ghost added this to the v0.13.0 milestone Jun 29, 2016
@ghost
Copy link

ghost commented Jun 29, 2016

Hi @klompenrunner,
This is currently resolved in scope of #483 (have a look at develop branch).

Thanks for the feedback.

@ghost ghost closed this as completed Jun 29, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

5 participants