mirror of
https://github.com/php/php-src.git
synced 2026-03-28 02:02:32 +01:00
The introduced checks did not treat "non-Unicode" encodings correctly, because they treated the passed integer as encoded in the internal encoding in that case, while in actuality the substitute character is always a Unicode codepoint. Additionally checking the codepoint against the internal encoding is not correct in any case, because the substitution character must be mapped in the *target* encoding of the conversion, which does not necessarily coincide with the internal encoding (the internal encoding is the default *source* encoding, not *target* encoding). This reverts the checks back to simple range checks, but in a way that still resolves #69079: Characters outside the Basic Multilingual Plane are now accepted and Surrogate Codepoints are rejected. A distinction between UTF-8 and non-UTF-8 encodings is not made for surrogate checks (as in the original patch), as surrogates are always illegal on their own. Specifying a surrogate as substitution character would only make sense if you could specify a substitution string with more than one character -- however we do not support that.
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
--TEST--
|
|
Test mb_substitute_character() function : basic functionality
|
|
--SKIPIF--
|
|
<?php
|
|
extension_loaded('mbstring') or die('skip');
|
|
function_exists('mb_substitute_character') or die("skip mb_substitute_character() is not available in this build");
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
/* Prototype : mixed mb_substitute_character([mixed substchar])
|
|
* Description: Sets the current substitute_character or returns the current substitute_character
|
|
* Source code: ext/mbstring/mbstring.c
|
|
* Alias to functions:
|
|
*/
|
|
|
|
echo "*** Testing mb_substitute_character() : basic functionality ***\n";
|
|
|
|
|
|
// Initialise all required variables
|
|
var_dump( mb_substitute_character() );
|
|
var_dump( mb_substitute_character(66) );
|
|
var_dump( mb_substitute_character() );
|
|
var_dump( mb_substitute_character(1234) );
|
|
var_dump( mb_substitute_character() );
|
|
var_dump( mb_substitute_character("none") );
|
|
var_dump( mb_substitute_character() );
|
|
var_dump( mb_substitute_character("b") );
|
|
|
|
?>
|
|
===DONE===
|
|
--EXPECTF--
|
|
*** Testing mb_substitute_character() : basic functionality ***
|
|
int(63)
|
|
bool(true)
|
|
int(66)
|
|
bool(true)
|
|
int(1234)
|
|
bool(true)
|
|
string(4) "none"
|
|
|
|
Warning: mb_substitute_character(): Unknown character in %s on line %d
|
|
bool(false)
|
|
===DONE===
|