Skip to content

Commit e36c973

Browse files
committed
Fix GH-12558 Escape \N and \n in generated stubs
1 parent f3d60a1 commit e36c973

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

build/gen_stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,10 @@ public function toOptimizerTypeMask(): string {
524524
}
525525

526526
public function toEscapedName(): string {
527-
// Escape backslashes, and also encode \u and \U to avoid compilation errors in generated macros
527+
// Escape backslashes, and also encode \u, \U, \n, and \N to avoid compilation errors in generated macros
528528
return str_replace(
529-
['\\', '\\u', '\\U'],
530-
['\\\\', '\\\\165', '\\\\125'],
529+
['\\', '\\u', '\\U', '\\n', '\\N'],
530+
['\\\\', '\\\\165', '\\\\125', '\\\\156', '\\\\116'],
531531
$this->name
532532
);
533533
}

ext/zend_test/test.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ class UnlikelyCompileError {
254254
public function method(): ?UnlikelyCompileError {}
255255
}
256256

257+
class NotUnlikelyCompileError {
258+
/* This method signature would create a compile error due to the string
259+
* "ZendTestNS\NotUnlikelyCompileError" in the generated macro call */
260+
public function method(): ?UnlikelyCompileError {}
261+
}
257262
}
258263

259264
namespace ZendTestNS2 {

ext/zend_test/test_arginfo.h

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zend_test/tests/gen_stub_test_01.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ $foo->foo = new \ZendTestNS2\ZendSubNS\Foo();
1111
var_dump($foo);
1212
$foo = new \ZendTestNS\UnlikelyCompileError();
1313
var_dump($foo);
14+
$foo = new \ZendTestNS\NotUnlikelyCompileError();
15+
var_dump($foo);
1416
?>
1517
--EXPECTF--
1618
object(ZendTestNS2\Foo)#%d (%d) {
@@ -24,3 +26,5 @@ object(ZendTestNS2\Foo)#%d (%d) {
2426
}
2527
object(ZendTestNS\UnlikelyCompileError)#%d (%d) {
2628
}
29+
object(ZendTestNS\NotUnlikelyCompileError)#%d (%d) {
30+
}

0 commit comments

Comments
 (0)