Skip to content

Encode special characters as XML entities #54

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
wants to merge 4 commits into from

Conversation

krtcom
Copy link
Contributor

@krtcom krtcom commented Oct 13, 2017

Sending EPP request containing special characters like '&' causes errors. This should fix it by encoding special characters as XML entities. Is it OK?

krtcom added 3 commits June 29, 2017 12:37
Allow underscore in xpath attributes (required for example in cz-nic (.cz) optional parameter)
Copy link
Member

@lifeofguenter lifeofguenter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look right. Setting the value via ->nodeValue automatically takes care of htmlentities, see also: https://stackoverflow.com/a/17332805/567193

If that is not the case, then there is somewhere else a bug - can you please produce a (failing) test case to proof & show the fault?

@krtcom
Copy link
Contributor Author

krtcom commented Oct 16, 2017

Yes, setting nodeValue on DOMText indeed takes care of xml entities but setting it on DOMElement (which are created in AbstractFrame) does convert only < and > characters. If value contains & it causes warning.

For example examples/update_contact.php

require '../vendor/autoload.php';

use AfriCC\EPP\Frame\Command\Update\Contact as UpdateContact;

$frame = new UpdateContact();
$frame->setId('C0054');
$frame->addOrganization('Father & Sons');

After running this I get this warning:

PHP Warning:  AfriCC\EPP\AbstractFrame::set(): unterminated entity reference Sons in php-epp2/src/AfriCC/EPP/AbstractFrame.php on line 62

Of course we could sanitize each value of every set/add/change call in entire application, but this looked like the easiest solution, since I am not aware of any side-effects of this method on the result.

Maybe just to be sure not to change the value too much it could be changed to
$this->nodes[$path]->nodeValue = str_replace("&", "&amp;", $value);

What do you think?

lifeofguenter added a commit to lifeofguenter/php-epp2 that referenced this pull request Dec 23, 2018
@lifeofguenter
Copy link
Member

sounds reasonable - I am dissecting this a bit - thanks for the contribution :) 👍

lifeofguenter added a commit that referenced this pull request Dec 23, 2018
* prepare for 1.0.0

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

Successfully merging this pull request may close these issues.

3 participants