]> granicus.if.org Git - php/commit
UTF-16 text conversion handles truncated characters as illegal
authorAlex Dowad <alexinbeijing@gmail.com>
Tue, 13 Oct 2020 13:17:00 +0000 (15:17 +0200)
committerAlex Dowad <alexinbeijing@gmail.com>
Tue, 27 Oct 2020 08:19:00 +0000 (10:19 +0200)
commitd9ddeb6e85d1dc3ddc3a0ea2e2014b2bc527e946
tree054bd3ba58edafedc253c1388b42096dc8dcce40
parent9bfb158872106eb3616dcc2056dfd86c02542f86
UTF-16 text conversion handles truncated characters as illegal

This broke one old test (Zend/tests/multibyte_encoding_003.phpt), which used
a PHP script encoded as UTF-16. The problem was that to terminate the test
script, we need the text: "\n--EXPECT--". Out of that text, the terminating
newline (0x0A byte) becomes part of the resulting test script; but a bare
0x0A byte with no 0x00 is not valid UTF-16.

Since we now treat truncated UTF-16 characters as erroneous, an extra '?' is
appended to the output as an 'illegal character' marker.

Really, if we are running PHP scripts which are treated as encoded in UTF-16
or some other arbitrary text encoding (not ASCII), and the script is not
actually a valid string in that encoding, inserting '?' characters into the
code which the PHP interpreter runs is a bad thing to do. In such cases, the
script shouldn't be treated as UTF-16 (or whatever) at all.

I wonder if mbstring's encoding detection is being used in 'non-strict' mode?
Zend/tests/multibyte/multibyte_encoding_003.phpt
ext/mbstring/libmbfl/filters/mbfilter_utf16.c