Skip to content

Commit

Permalink
Properly and consistently strip only CRLF at end
Browse files Browse the repository at this point in the history
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
  • Loading branch information
michael-o committed Oct 19, 2022
1 parent 943b82a commit a923114
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions blame.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@

while (!feof($blame) && !feof($file))
{
$blameline = fgets($blame);
$blameline = rtrim(fgets($blame), "\n\r");

if ($blameline != '')
{
Expand All @@ -207,7 +207,7 @@
$listvar['row_class'] = $row_class;
$last_rev = $revision;

$line = rtrim(fgets($file));
$line = rtrim(fgets($file), "\n\r");
if (!$highlighted)
{
$line = escape(toOutputEncoding($line));
Expand Down
10 changes: 5 additions & 5 deletions comp.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ function clearVars()
{
if ($bufferedLine === false)
{
$bufferedLine = rtrim(fgets($diff), "\r\n");
$bufferedLine = rtrim(fgets($diff), "\n\r");
}

$newlineR = strpos($bufferedLine, "\r");
Expand Down Expand Up @@ -494,7 +494,7 @@ function clearVars()
{
$index++;
clearVars();
$listing[$index++]['info'] = escape(toOutputEncoding($line));
$listing[$index++]['info'] = escape(toOutputEncoding(rtrim($line, "\n\r")));
continue;
}

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

while ($line = trim(fgets($diff)))
while ($line = rtrim(fgets($diff), "\n\r"))
{
if (!strncmp($line, 'Index: ', 7))
if (!strncmp(trim($line), 'Index: ', 7))
{
break;
}
if (!strncmp($line, '##', 2) || $line == '\ No newline at end of file')
if (!strncmp(trim($line), '##', 2) || $line == '\ No newline at end of file')
{
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions include/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ function runCommand($cmd, $mayReturnNothing = false, &$errorIf = 'NOT_USED') {
$firstline = true;

while (!feof($handle)) {
$line = fgets($handle);
$line = rtrim(fgets($handle), "\n\r");
if ($firstline && empty($line) && !$mayReturnNothing) {
$error = 'No output on STDOUT.';
break;
}

$firstline = false;
$output[] = toOutputEncoding(rtrim($line));
$output[] = toOutputEncoding($line);
}

while (!feof($pipes[2])) {
Expand Down
3 changes: 1 addition & 2 deletions include/diff_inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function diff_result($all, $highlighted, $newtname, $oldtname, $obj, $ignoreWhit
$fin = true;
} else {
$mod = $line[0];
$line = rtrim(substr($line, 1));
$line = substr($line, 1);

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

$text1 = getWrappedLineFromFile($ofile, $highlighted);
$text2 = getWrappedLineFromFile($nfile, $highlighted);

$listingHelper->addLine($text1, $curoline, $text2, $curnline);

$curoline++;
Expand Down
6 changes: 0 additions & 6 deletions include/svnlook.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,7 @@ function listCharacterData($parser, $data) {

case 'DATE':
if ($debugxml) print 'Date: '.$data."\n";
$data = trim($data);
if ($data === false || $data === '') return;

$committime = parseSvnTimestamp($data);
$curList->curEntry->committime = $committime;
$curList->curEntry->date = date('Y-m-d H:i:s', $committime);
Expand Down Expand Up @@ -439,9 +437,7 @@ function logCharacterData($parser, $data) {

case 'DATE':
if ($debugxml) print 'Date: '.$data."\n";
$data = trim($data);
if ($data === false || $data === '') return;

$committime = parseSvnTimestamp($data);
$curLog->curEntry->committime = $committime;
$curLog->curEntry->date = date('Y-m-d H:i:s', $committime);
Expand All @@ -457,9 +453,7 @@ function logCharacterData($parser, $data) {

case 'PATH':
if ($debugxml) print 'Path name: '.$data."\n";
$data = trim($data);
if ($data === false || $data === '') return;

$curLog->curEntry->curMod->path .= $data;
break;
}
Expand Down

0 comments on commit a923114

Please sign in to comment.