Skip to content

Commit 5530139

Browse files
committed
gen_stub: strip dollar sign escape sequence
C doesn't have this, and will throw the following warning/error: ``` error: unknown escape sequence '\$' [-Werror,-Wunknown-escape-sequence] ``` Since adding this to zend_test for CI's sake, this will bomb out. Strip this specific sequence out to make cc happy.
1 parent bac65c9 commit 5530139

5 files changed

Lines changed: 31 additions & 9 deletions

File tree

build/gen_stub.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2348,16 +2348,23 @@ public function getCExpr(): ?string
23482348
// The string in $expr has had the octal, hex, and unicode
23492349
// backslash sequences already applied for double-quoted strings,
23502350
// but not the other sequences.
2351+
//
23512352
// PHP has single quote strings, C doesn't (they're one char).
23522353
// Single-quoted strings need handling to replace their escapes
23532354
// with the double-quoted equivalent; namely single quote escapes.
2355+
//
23542356
// Double-quoted strings have similar escape sequences as C does,
2355-
// so we can pass them through directly.
2357+
// so we can pass them through directly. However, C does *not*
2358+
// support the \$ escape sequence (in ""), so strip that. Variable
2359+
// interpolation shouldn't be possible in a stub, so we don't need
2360+
// to worry about mangling such a case.
23562361
if (preg_match("/(^'|'$)/", $expr)) {
23572362
$expr = substr($expr, 1, -1); // strip quotes, readd later
23582363
$expr = str_replace("\\'", "'", $expr);
23592364
$expr = addcslashes($expr, "\\\"");
23602365
$expr = "\"$expr\"";
2366+
} else {
2367+
$expr = str_replace('\$', "$", $expr);
23612368
}
23622369
}
23632370
return $expr[0] == '"' ? $expr : preg_replace('(\bnull\b)', 'NULL', str_replace('\\', '', $expr));

ext/zend_test/test.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class _ZendTestClass implements _ZendTestInterface {
6363
* the generated header won't compile. */
6464
public static string $doubleQuoteEscaped = "BEGIN \n\r\t\v\e\f\\\$\"\101\x41\u{41} END";
6565
public static string $singleQuoteEscaped = 'BEGIN \n\r\t\v\e\f\\\$\"\101\x41\u{41} END';
66+
public static string $escapeInterpolated = "begin \$ \\$ end";
6667

6768
public int $intProp = 123;
6869
public ?stdClass $classProp = null;

ext/zend_test/test_arginfo.h

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zend_test/test_decl.h

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

ext/zend_test/test_legacy_arginfo.h

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)