Skip to content

Commit a923114

Browse files
committed
Properly and consistently strip only CRLF at end
fgets() and file_get_contents() give us lines with retained line separators. So we need to trim those and *only* those instead of other whitespace chars. This fixes #181 and closes #183
1 parent 943b82a commit a923114

5 files changed

Lines changed: 10 additions & 17 deletions

File tree

blame.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181

182182
while (!feof($blame) && !feof($file))
183183
{
184-
$blameline = fgets($blame);
184+
$blameline = rtrim(fgets($blame), "\n\r");
185185

186186
if ($blameline != '')
187187
{
@@ -207,7 +207,7 @@
207207
$listvar['row_class'] = $row_class;
208208
$last_rev = $revision;
209209

210-
$line = rtrim(fgets($file));
210+
$line = rtrim(fgets($file), "\n\r");
211211
if (!$highlighted)
212212
{
213213
$line = escape(toOutputEncoding($line));

comp.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ function clearVars()
326326
{
327327
if ($bufferedLine === false)
328328
{
329-
$bufferedLine = rtrim(fgets($diff), "\r\n");
329+
$bufferedLine = rtrim(fgets($diff), "\n\r");
330330
}
331331

332332
$newlineR = strpos($bufferedLine, "\r");
@@ -494,7 +494,7 @@ function clearVars()
494494
{
495495
$index++;
496496
clearVars();
497-
$listing[$index++]['info'] = escape(toOutputEncoding($line));
497+
$listing[$index++]['info'] = escape(toOutputEncoding(rtrim($line, "\n\r")));
498498
continue;
499499
}
500500

@@ -537,13 +537,13 @@ function clearVars()
537537
$line = fgets($diff);
538538
if ($debug) print 'Skipping: '.$line.'<br />';
539539

540-
while ($line = trim(fgets($diff)))
540+
while ($line = rtrim(fgets($diff), "\n\r"))
541541
{
542-
if (!strncmp($line, 'Index: ', 7))
542+
if (!strncmp(trim($line), 'Index: ', 7))
543543
{
544544
break;
545545
}
546-
if (!strncmp($line, '##', 2) || $line == '\ No newline at end of file')
546+
if (!strncmp(trim($line), '##', 2) || $line == '\ No newline at end of file')
547547
{
548548
continue;
549549
}

include/command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ function runCommand($cmd, $mayReturnNothing = false, &$errorIf = 'NOT_USED') {
142142
$firstline = true;
143143

144144
while (!feof($handle)) {
145-
$line = fgets($handle);
145+
$line = rtrim(fgets($handle), "\n\r");
146146
if ($firstline && empty($line) && !$mayReturnNothing) {
147147
$error = 'No output on STDOUT.';
148148
break;
149149
}
150150

151151
$firstline = false;
152-
$output[] = toOutputEncoding(rtrim($line));
152+
$output[] = toOutputEncoding($line);
153153
}
154154

155155
while (!feof($pipes[2])) {

include/diff_inc.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function diff_result($all, $highlighted, $newtname, $oldtname, $obj, $ignoreWhit
175175
$fin = true;
176176
} else {
177177
$mod = $line[0];
178-
$line = rtrim(substr($line, 1));
178+
$line = substr($line, 1);
179179

180180
switch ($mod) {
181181
case '-':
@@ -195,7 +195,6 @@ function diff_result($all, $highlighted, $newtname, $oldtname, $obj, $ignoreWhit
195195

196196
$text1 = getWrappedLineFromFile($ofile, $highlighted);
197197
$text2 = getWrappedLineFromFile($nfile, $highlighted);
198-
199198
$listingHelper->addLine($text1, $curoline, $text2, $curnline);
200199

201200
$curoline++;

include/svnlook.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@ function listCharacterData($parser, $data) {
288288

289289
case 'DATE':
290290
if ($debugxml) print 'Date: '.$data."\n";
291-
$data = trim($data);
292291
if ($data === false || $data === '') return;
293-
294292
$committime = parseSvnTimestamp($data);
295293
$curList->curEntry->committime = $committime;
296294
$curList->curEntry->date = date('Y-m-d H:i:s', $committime);
@@ -439,9 +437,7 @@ function logCharacterData($parser, $data) {
439437

440438
case 'DATE':
441439
if ($debugxml) print 'Date: '.$data."\n";
442-
$data = trim($data);
443440
if ($data === false || $data === '') return;
444-
445441
$committime = parseSvnTimestamp($data);
446442
$curLog->curEntry->committime = $committime;
447443
$curLog->curEntry->date = date('Y-m-d H:i:s', $committime);
@@ -457,9 +453,7 @@ function logCharacterData($parser, $data) {
457453

458454
case 'PATH':
459455
if ($debugxml) print 'Path name: '.$data."\n";
460-
$data = trim($data);
461456
if ($data === false || $data === '') return;
462-
463457
$curLog->curEntry->curMod->path .= $data;
464458
break;
465459
}

0 commit comments

Comments
 (0)