Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7032191

Browse files
[VarDumper] Fix indentation trimming in ExceptionCaster
1 parent fe17083 commit 7032191

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,24 @@ private static function extractSource(array $srcArray, $line, $srcContext)
253253
}
254254

255255
$ltrim = 0;
256-
while (' ' === $src[0][$ltrim] || "\t" === $src[0][$ltrim]) {
257-
$i = $srcContext << 1;
258-
while ($i > 0 && $src[0][$ltrim] === $src[$i][$ltrim]) {
259-
--$i;
260-
}
261-
if ($i) {
262-
break;
256+
do {
257+
$pad = null;
258+
for ($i = $srcContext << 1; $i >= 0; --$i) {
259+
if (isset($src[$i][$ltrim]) && "\r" !== ($c = $src[$i][$ltrim]) && "\n" !== $c) {
260+
if (null === $pad) {
261+
$pad = $c;
262+
}
263+
if ((' ' !== $c && "\t" !== $c) || $pad !== $c) {
264+
break;
265+
}
266+
}
263267
}
264268
++$ltrim;
265-
}
266-
if ($ltrim) {
269+
} while (0 > $i && null !== $pad);
270+
271+
if (--$ltrim) {
267272
foreach ($src as $i => $line) {
268-
$src[$i] = substr($line, $ltrim);
273+
$src[$i] = isset($line[$ltrim]) && "\r" !== $line[$ltrim] ? substr($line, $ltrim) : ltrim($line, " \t");
269274
}
270275
}
271276

src/Symfony/Component/VarDumper/Tests/CliDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function testThrowingCaster()
200200
$twig = <<<EOTXT
201201
foo.twig:2: """
202202
foo bar\\n
203-
twig source\\n
203+
twig source\\n
204204
\\n
205205
"""
206206

src/Symfony/Component/VarDumper/Tests/Fixtures/Twig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public function getDebugInfo()
2929
return array (19 => 2);
3030
}
3131
}
32-
/* foo bar*/
32+
/* foo bar*/
3333
/* twig source*/
3434
/* */

0 commit comments

Comments
 (0)