Don't Use htmlspecialchars When Formatting Xml #4540
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #4537. PhpSpreadsheet currently changes apostrophes in text values to
'
. This is perfectly valid Xml. Issue was opened because R does not handle this correctly; this is unquestionably a bug on R's part. So I was not inclined to do anything about it. However ...User suggested a change to how
htmlspecialchars
was called. Investigating the use of that routine in PhpSpreadsheet, I found that there was some double escaping going on for cells whose type was set toTYPE_INLINE
-htmlspecialchars
escaped the string correctly, but it was later written as Xml using a method which escaped the data a second time. So, a real bug in PhpSpreadsheet after all.There was one call to
htmlspecialchars
inShared\XmlWriter
. I replacedwriteRaw(htmlspecialchars(...))
withtext(...)
. And one call inWriter\Xlsx\Worksheet
, the source of the double escaping bug above; the call tohtmlspecialchars
can just be eliminated there.Making those changes, the only remaining calls to
htmlspecialchars
are inWriter\Html
, where they belong. As a bonus, apostrophes now wind up unescaped, so R will be satisfied (even though they should fix their bug).This is:
Checklist: