[php-src] Issue #11663: `DOMDocument` / `SimpleXMLElement` incorrectly convert UTF-8 input when using ISO-8859-15 encoding
| From: | filecage | Date: | Mon, 10 Jul 2023 14:17:47 +0000 |
| Subject: | [php-src] Issue #11663: `DOMDocument` / `SimpleXMLElement` incorrectly convert UTF-8 input when using ISO-8859-15 encoding | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244934@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11663
Author: filecage
### Description
## Description
When I'm passing non-convertable UTF-8 characters into a
DOMDocument node that has
been initialized with an encoding like ISO-8859-15, I expect the library to correctly handle these
characters. As in such a case where they are non-printable, I expect them to be encoded in HTML
entitites.
This is what happens when my DOMDocument encoding is ISO-8859-1. However, it does not
work correctly when I'm using ISO-8859-15.
## Example
The following code:
```php
<?php
// Decimal Unicode Code Points: 8224, 8225, 8482, 49, 50, 51
$input = '†‡™123';
// Correct output -> the UTF-8-only characters are encoded as HTML entitites
$domISO88591 = new DOMDocument('1.0', 'ISO-8859-1');
$domISO88591->appendChild($domISO88591->createElement('text', $input));
echo $domISO88591->saveXML();
// Incorrect output
$domISO885915 = new DOMDocument('1.0', 'ISO-8859-15');
$domISO885915->appendChild($domISO885915->createElement('text', $input));
echo $domISO885915->saveXML();
```
### Result
```
<?xml version="1.0" encoding="ISO-8859-1"?>
<text>†‡™123</text>
<?xml version="1.0" encoding="ISO-8859-15"?>
<text>‡123</text>
```
**Problem:** The † and ™ are omitted and somehow the 1
has been incorrectly converted to 1.
### Expected Output
```
<?xml version="1.0" encoding="ISO-8859-1"?>
<text>†‡™123</text>
<?xml version="1.0" encoding="ISO-8859-15"?>
<text>†‡™123</text>
```
Both outputs should be exactly the same because, given the input, both ISO encodings share the same
set of printable characters. Also, all printable characters should not be encoded to HTML entitites
(as with 1 and 1)
## Affected Versions
All of my local PHP binaries are affected, with the newest version being 8.2.8 and the oldest being
7.4.15.
### PHP Version
PHP 8.2.8
### Operating System
macOS 13.4, libxml 2.9.4