Skip to content

Commit

Permalink
Add workaround for escape char issue (esp. with namespaces)
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Feb 20, 2025
1 parent f70f67c commit 05b81b8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/midcom/datamanager/validation/phpValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ public static function lint(string $input) : ?string
{
$return_status = 0;
$parse_results = [];
exec(sprintf('echo %s | php -l', escapeshellarg($input)) . " 2>&1", $parse_results, $return_status);

// Not all shells seem to support disabling escape characters, so
// enable them everywhere with -e and mask them instead
$input = str_replace(
['\a', '\b', '\c', '\e', '\f', '\n', '\r', '\t', '\v'],
[ '\\\a', '\\\b', '\\\c', '\\\e', '\\\f', '\\\n', '\\\r', '\\\t', '\\\v'],
$input
);
exec(sprintf('echo -e %s | php -l', escapeshellarg($input)) . " 2>&1", $parse_results, $return_status);
debug_print_r("php -l returned:", $parse_results);

if ($return_status !== 0) {
$parse_result = array_pop($parse_results);
if (str_contains($parse_result, 'No syntax errors detected in ')) {
Expand Down

0 comments on commit 05b81b8

Please sign in to comment.