Fix GH-12558 Escape \N in generated stubs (#12562)

This commit is contained in:
Máté Kocsis 2023-10-31 10:06:56 +01:00 committed by GitHub
parent 4b82ed4387
commit d4e40dc0e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 4 deletions

2
NEWS
View file

@ -10,6 +10,8 @@ PHP NEWS
property via trait). (ilutov)
. Fixed segfault caused by weak references to FFI objects. (sj-i)
. Fixed max_execution_time: don't delete an unitialized timer. (Kévin Dunglas)
. Fixed bug GH-12558 (Arginfo soft-breaks with namespaced class return type
if the class name starts with N). (kocsismate)
- DOM:
. Fix registerNodeClass with abstract class crashing. (nielsdos)

View file

@ -527,10 +527,10 @@ class SimpleType {
}
public function toEscapedName(): string {
// Escape backslashes, and also encode \u and \U to avoid compilation errors in generated macros
// Escape backslashes, and also encode \u, \U, and \N to avoid compilation errors in generated macros
return str_replace(
['\\', '\\u', '\\U'],
['\\\\', '\\\\165', '\\\\125'],
['\\', '\\u', '\\U', '\\N'],
['\\\\', '\\\\165', '\\\\125', '\\\\116'],
$this->name
);
}

View file

@ -52,6 +52,7 @@ static zend_class_entry *zend_test_child_class_with_method_with_parameter_attrib
static zend_class_entry *zend_test_forbid_dynamic_call;
static zend_class_entry *zend_test_ns_foo_class;
static zend_class_entry *zend_test_ns_unlikely_compile_error_class;
static zend_class_entry *zend_test_ns_not_unlikely_compile_error_class;
static zend_class_entry *zend_test_ns2_foo_class;
static zend_class_entry *zend_test_ns2_ns_foo_class;
static zend_class_entry *zend_test_unit_enum;
@ -636,6 +637,13 @@ static ZEND_METHOD(ZendTestNS_UnlikelyCompileError, method)
RETURN_NULL();
}
static ZEND_METHOD(ZendTestNS_NotUnlikelyCompileError, method)
{
ZEND_PARSE_PARAMETERS_NONE();
RETURN_NULL();
}
static ZEND_METHOD(ZendTestNS2_Foo, method)
{
ZEND_PARSE_PARAMETERS_NONE();
@ -818,6 +826,7 @@ PHP_MINIT_FUNCTION(zend_test)
zend_test_ns_foo_class = register_class_ZendTestNS_Foo();
zend_test_ns_unlikely_compile_error_class = register_class_ZendTestNS_UnlikelyCompileError();
zend_test_ns_not_unlikely_compile_error_class = register_class_ZendTestNS_NotUnlikelyCompileError();
zend_test_ns2_foo_class = register_class_ZendTestNS2_Foo();
zend_test_ns2_ns_foo_class = register_class_ZendTestNS2_ZendSubNS_Foo();

View file

@ -190,6 +190,11 @@ namespace ZendTestNS {
public function method(): ?UnlikelyCompileError {}
}
class NotUnlikelyCompileError {
/* This method signature would create a compile error due to the string
* "ZendTestNS\NotUnlikelyCompileError" in the generated macro call */
public function method(): ?NotUnlikelyCompileError {}
}
}
namespace ZendTestNS2 {

View file

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: fa6d8c58bdef20c6c9c8db75dbb6ede775324193 */
* Stub hash: 37c6d5e5e28a60b3d1cf89c1a2f82a0196fceae7 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
@ -171,6 +171,9 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ZendTestNS_UnlikelyCompileError_method, 0, 0, ZendTestNS\\\125nlikelyCompileError, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ZendTestNS_NotUnlikelyCompileError_method, 0, 0, ZendTestNS\\\116otUnlikelyCompileError, 1)
ZEND_END_ARG_INFO()
#define arginfo_class_ZendTestNS2_Foo_method arginfo_zend_test_void_return
#define arginfo_class_ZendTestNS2_ZendSubNS_Foo_method arginfo_zend_test_void_return
@ -225,6 +228,7 @@ static ZEND_METHOD(ZendTestForbidDynamicCall, call);
static ZEND_METHOD(ZendTestForbidDynamicCall, callStatic);
static ZEND_METHOD(ZendTestNS_Foo, method);
static ZEND_METHOD(ZendTestNS_UnlikelyCompileError, method);
static ZEND_METHOD(ZendTestNS_NotUnlikelyCompileError, method);
static ZEND_METHOD(ZendTestNS2_Foo, method);
static ZEND_METHOD(ZendTestNS2_ZendSubNS_Foo, method);
@ -364,6 +368,12 @@ static const zend_function_entry class_ZendTestNS_UnlikelyCompileError_methods[]
};
static const zend_function_entry class_ZendTestNS_NotUnlikelyCompileError_methods[] = {
ZEND_ME(ZendTestNS_NotUnlikelyCompileError, method, arginfo_class_ZendTestNS_NotUnlikelyCompileError_method, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
static const zend_function_entry class_ZendTestNS2_Foo_methods[] = {
ZEND_ME(ZendTestNS2_Foo, method, arginfo_class_ZendTestNS2_Foo_method, ZEND_ACC_PUBLIC)
ZEND_FE_END
@ -698,6 +708,16 @@ static zend_class_entry *register_class_ZendTestNS_UnlikelyCompileError(void)
return class_entry;
}
static zend_class_entry *register_class_ZendTestNS_NotUnlikelyCompileError(void)
{
zend_class_entry ce, *class_entry;
INIT_NS_CLASS_ENTRY(ce, "ZendTestNS", "NotUnlikelyCompileError", class_ZendTestNS_NotUnlikelyCompileError_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
return class_entry;
}
static zend_class_entry *register_class_ZendTestNS2_Foo(void)
{
zend_class_entry ce, *class_entry;

View file

@ -11,6 +11,8 @@ $foo->foo = new \ZendTestNS2\ZendSubNS\Foo();
var_dump($foo);
$foo = new \ZendTestNS\UnlikelyCompileError();
var_dump($foo);
$foo = new \ZendTestNS\NotUnlikelyCompileError();
var_dump($foo);
?>
--EXPECTF--
object(ZendTestNS2\Foo)#%d (%d) {
@ -24,3 +26,5 @@ object(ZendTestNS2\Foo)#%d (%d) {
}
object(ZendTestNS\UnlikelyCompileError)#%d (%d) {
}
object(ZendTestNS\NotUnlikelyCompileError)#%d (%d) {
}