mirror of
https://github.com/php/php-src.git
synced 2025-01-23 20:23:31 +08:00
fix #43941: invalid utf-8 not accepted
This commit is contained in:
parent
6a455ee097
commit
b4443f35ff
@ -269,8 +269,14 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options) /*
|
||||
{
|
||||
efree(utf16);
|
||||
}
|
||||
|
||||
smart_str_appendl(buf, "\"\"", 2);
|
||||
if(len < 0) {
|
||||
if(!PG(display_errors)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid UTF-8 sequence in argument");
|
||||
}
|
||||
smart_str_appendl(buf, "null", 4);
|
||||
} else {
|
||||
smart_str_appendl(buf, "\"\"", 2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
21
ext/json/tests/bug43941.phpt
Normal file
21
ext/json/tests/bug43941.phpt
Normal file
@ -0,0 +1,21 @@
|
||||
--TEST--
|
||||
Bug #43941 (json_encode() invalid UTF-8)
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
var_dump(json_encode("abc"));
|
||||
var_dump(json_encode("ab\xE0"));
|
||||
var_dump(json_encode("ab\xE0c"));
|
||||
var_dump(json_encode(array("ab\xE0", "ab\xE0c", "abc")));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(5) ""abc""
|
||||
string(4) "null"
|
||||
string(4) "null"
|
||||
string(17) "[null,null,"abc"]"
|
||||
Done
|
||||
|
@ -40,7 +40,7 @@ utf8_to_utf16(unsigned short w[], char p[], int length)
|
||||
for (;;) {
|
||||
c = utf8_decode_next(&utf8);
|
||||
if (c < 0) {
|
||||
return UTF8_END ? the_index : UTF8_ERROR;
|
||||
return (c == UTF8_END) ? the_index : UTF8_ERROR;
|
||||
}
|
||||
if (c < 0x10000) {
|
||||
w[the_index] = (unsigned short)c;
|
||||
|
Loading…
Reference in New Issue
Block a user