bug #19288 [VarDumper] Fix indentation trimming in ExceptionCaster (nicolas-grekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[VarDumper] Fix indentation trimming in ExceptionCaster

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Blank lines prevent left-trimming of source code excerpts currently.

Commits
-------

ab9daeb [VarDumper] Fix indentation trimming in ExceptionCaster
This commit is contained in:
Nicolas Grekas 2016-07-05 13:02:43 +02:00
commit 4e7cc3b98e
4 changed files with 19 additions and 14 deletions

View File

@ -253,19 +253,24 @@ class ExceptionCaster
}
$ltrim = 0;
while (' ' === $src[0][$ltrim] || "\t" === $src[0][$ltrim]) {
$i = $srcContext << 1;
while ($i > 0 && $src[0][$ltrim] === $src[$i][$ltrim]) {
--$i;
do {
$pad = null;
for ($i = $srcContext << 1; $i >= 0; --$i) {
if (isset($src[$i][$ltrim]) && "\r" !== ($c = $src[$i][$ltrim]) && "\n" !== $c) {
if (null === $pad) {
$pad = $c;
}
if ($i) {
if ((' ' !== $c && "\t" !== $c) || $pad !== $c) {
break;
}
++$ltrim;
}
if ($ltrim) {
}
++$ltrim;
} while (0 > $i && null !== $pad);
if (--$ltrim) {
foreach ($src as $i => $line) {
$src[$i] = substr($line, $ltrim);
$src[$i] = isset($line[$ltrim]) && "\r" !== $line[$ltrim] ? substr($line, $ltrim) : ltrim($line, " \t");
}
}