Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Serializer] Fix: Report Xml warning/error instead of silently returning a wrong xml#54346

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:7.1fromVincentLanglet:saveXmlWarning
Apr 5, 2024

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLangletVincentLanglet commentedMar 20, 2024
edited
Loading

QA
Branch?7.1
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix #...
LicenseMIT

WhenDomDocument::saveXML encounter an error/warning, for example

DOMDocument::saveXML(): xmlEscapeEntities : char out of range

the method will return false or an empty/incomplete XML.

In case offalse, since symfony doesn't use strict type, it will be cast intostring (for 6.4+ version with native typehint) so theencode method will return an empty string.
In case of empty/incomplete XML, symfony returns it as if, without any notice about the error/warning.

I think Symfony should not silently ignore such XML error when decoding.

Or should it be an option ?

@VincentLanglet
Copy link
ContributorAuthor

Others failure (especially lint) are unrelated.
I don't touch them to minize the conflict with up-merge.

@nicolas-grekas
Copy link
Member

Don't we get an exception from ErrorHandler in debug mode at the moment?
Let's do this on 7.1 so that we're confident we won't break any existing apps?

@VincentLanglet
Copy link
ContributorAuthor

Don't we get an exception from ErrorHandler in debug mode at the moment?

Yes, but not in production. So it silently return a wrong xml in prod.

Let's do this on 7.1 so that we're confident we won't break any existing apps?

Ok for 7.1. Should I do the PR like this or with an option to passe to the encoder@nicolas-grekas ?

@nicolas-grekas
Copy link
Member

No options on my side.

@VincentLanglet
Copy link
ContributorAuthor

Let's do this on 7.1 so that we're confident we won't break any existing apps?

Done@nicolas-grekas :)

@nicolas-grekasnicolas-grekas modified the milestones:5.4,7.1Mar 21, 2024
$ignorePiNode =\in_array(\XML_PI_NODE,$encoderIgnoredNodeTypes,true);
if ($datainstanceof \DOMDocument) {
return$data->saveXML($ignorePiNode ?$data->documentElement :null);
set_error_handler(staticfunction ($type,$message) {thrownewNotEncodableValueException($message); }, \E_ERROR | \E_WARNING);

Choose a reason for hiding this comment

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

that doesn't work: php won't fallback on the previous handler for deprecation
instead, I suggest using the@ operator and using error_get_last to compute the exception message when needed

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

$result = @$data->saveXML($ignorePiNode ? $data->documentElement : null);if (false === $result) {    throw Exception();}

doesn't cover all the case.

For instance

$dom = new DOMDocument();$root = $dom->createElement('root');$dom->appendChild($root);$text = $dom->createTextNode("Invalid character: " . chr(7));$root->appendChild($text);$saved = $dom->saveXML();// Check if saving was successfulif ($saved === false) {    echo "Error saving XML\n";} else {    echo "XML saved successfully\n";    echo $saved;}

gives

Warning: DOMDocument::saveXML(): xmlEscapeEntities : char out of range in /home/user/scripts/code.php on line 9XML saved successfully<?xml version="1.0"?><root></root>

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

It should be better with41c83a3@nicolas-grekas

@fabpot
Copy link
Member

Thank you@VincentLanglet.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@mtarldmtarldmtarld approved these changes

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

@lyrixxlyrixxAwaiting requested review from lyrixx

@ycerutoycerutoAwaiting requested review from yceruto

@chalasrchalasrAwaiting requested review from chalasr

@xabbuhxabbuhAwaiting requested review from xabbuh

@stofstofAwaiting requested review from stof

@nicolas-grekasnicolas-grekasAwaiting requested review from nicolas-grekas

Assignees

No one assigned

Projects

None yet

Milestone

7.1

Development

Successfully merging this pull request may close these issues.

6 participants

@VincentLanglet@nicolas-grekas@fabpot@stof@mtarld@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp