From d4e40dc0e1dc48533fc42ec167d99f8cad64ae37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 31 Oct 2023 10:06:56 +0100 Subject: [PATCH] Fix GH-12558 Escape \N in generated stubs (#12562) --- NEWS | 2 ++ build/gen_stub.php | 6 +++--- ext/zend_test/test.c | 9 +++++++++ ext/zend_test/test.stub.php | 5 +++++ ext/zend_test/test_arginfo.h | 22 +++++++++++++++++++++- ext/zend_test/tests/gen_stub_test_01.phpt | 4 ++++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index c1f6557de10..a09e3081741 100644 --- a/NEWS +++ b/NEWS @@ -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) diff --git a/build/gen_stub.php b/build/gen_stub.php index 7df52908836..0c745c8c030 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -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 ); } diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index 88b7d5d904e..4371459a910 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -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(); diff --git a/ext/zend_test/test.stub.php b/ext/zend_test/test.stub.php index 5ebe6b574b6..eaed7e2794a 100644 --- a/ext/zend_test/test.stub.php +++ b/ext/zend_test/test.stub.php @@ -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 { diff --git a/ext/zend_test/test_arginfo.h b/ext/zend_test/test_arginfo.h index 5a3af3879d7..72b89ef3334 100644 --- a/ext/zend_test/test_arginfo.h +++ b/ext/zend_test/test_arginfo.h @@ -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; diff --git a/ext/zend_test/tests/gen_stub_test_01.phpt b/ext/zend_test/tests/gen_stub_test_01.phpt index 0a020a6f345..0f5d525322d 100644 --- a/ext/zend_test/tests/gen_stub_test_01.phpt +++ b/ext/zend_test/tests/gen_stub_test_01.phpt @@ -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) { +}