Skip to content

Fix GH-12558 Escape \N and \n in generated stubs #12562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,10 @@ public function toOptimizerTypeMask(): string {
}

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
);
}
Expand Down
9 changes: 9 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
5 changes: 5 additions & 0 deletions ext/zend_test/test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ class UnlikelyCompileError {
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 {
Expand Down
22 changes: 21 additions & 1 deletion ext/zend_test/test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ext/zend_test/tests/gen_stub_test_01.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -24,3 +26,5 @@ object(ZendTestNS2\Foo)#%d (%d) {
}
object(ZendTestNS\UnlikelyCompileError)#%d (%d) {
}
object(ZendTestNS\NotUnlikelyCompileError)#%d (%d) {
}