Skip to content
Snippets Groups Projects
Commit 2c72e747 authored by Andreas Kienast's avatar Andreas Kienast
Browse files

[BUGFIX] Handle excess whitespace characters in `CommandUtility::exec()`

PHP's behavior of `exec()` [1] is flabbergasting: when writing the
buffer, trailing whitespace characters are trimmed as follows:

1. the last PHP_EOL character is chopped
2. any left-over trailing literal space characters are trimmed

Neither of this was handled in the implementation introduced
in #104045, leading to unexpected output.

This commit emulates the behavior of PHP's internal `exec()` function,
restoring the previous behavior of `CommandUtility::exec()`.

[1] https://github.com/php/php-src/blob/master/ext/standard/exec.c

Resolves: #105251
Related: #104045
Releases: main
Change-Id: I726b6ac0214f2cb3983db7b66c366a1fa58f93f8
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/86533


Reviewed-by: default avatarBenjamin Kott <benjamin.kott@outlook.com>
Tested-by: default avatarBenjamin Kott <benjamin.kott@outlook.com>
Tested-by: default avatarBenjamin Franzke <ben@bnf.dev>
Tested-by: default avatarcore-ci <typo3@b13.com>
Reviewed-by: default avatarAndreas Kienast <akienast@scripting-base.de>
Tested-by: default avatarAndreas Kienast <akienast@scripting-base.de>
Reviewed-by: default avatarBenjamin Franzke <ben@bnf.dev>
parent d604d241
Branches
No related merge requests found
......@@ -108,9 +108,15 @@ class CommandUtility
return false;
}
$output = explode(PHP_EOL, $process->getOutput());
$processOutput = $process->getOutput();
if (str_ends_with($processOutput, PHP_EOL)) {
// Last \n is ignored by PHP exec(): https://github.com/php/php-src/blob/b675db4c56dd0de4ea1f5195d587ed90f0096ed8/ext/standard/exec.c#L148
$processOutput = substr($processOutput, 0, -1);
}
$output = explode(PHP_EOL, $processOutput);
return rtrim(strrchr($processOutput, PHP_EOL) ?: $processOutput);
return $output[count($output) - 1] ?? '';
}
/**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment