2.0.0-rc.8

This commit is contained in:
Rodrigo Fernandes 2016-06-28 22:19:44 +01:00
parent 8679bc354d
commit 8fe49abaa4
4 changed files with 60 additions and 39 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "diff2html", "name": "diff2html",
"version": "2.0.0-rc.7", "version": "2.0.0-rc.8",
"homepage": "http://rtfpessoa.github.io/diff2html/", "homepage": "http://rtfpessoa.github.io/diff2html/",
"description": "Fast Diff to colorized HTML", "description": "Fast Diff to colorized HTML",
"keywords": [ "keywords": [

54
dist/diff2html.js vendored
View file

@ -2478,6 +2478,11 @@ var Hogan = {};
.replace(/\r\n?/g, '\n') .replace(/\r\n?/g, '\n')
.split('\n'); .split('\n');
/* Diff Header */
var oldFileNameHeader = '--- ';
var newFileNameHeader = '+++ ';
var hunkHeaderPrefix = '@@';
/* Diff */ /* Diff */
var oldMode = /^old mode (\d{6})/; var oldMode = /^old mode (\d{6})/;
var newMode = /^new mode (\d{6})/; var newMode = /^new mode (\d{6})/;
@ -2500,7 +2505,7 @@ var Hogan = {};
var combinedNewFile = /^new file mode (\d{6})/; var combinedNewFile = /^new file mode (\d{6})/;
var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/; var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/;
diffLines.forEach(function(line) { diffLines.forEach(function(line, lineIndex) {
// Unmerged paths, and possibly other non-diffable files // Unmerged paths, and possibly other non-diffable files
// https://github.com/scottgonzalez/pretty-diff/issues/11 // https://github.com/scottgonzalez/pretty-diff/issues/11
// Also, remove some useless lines // Also, remove some useless lines
@ -2508,14 +2513,23 @@ var Hogan = {};
return; return;
} }
if ( var prevLine = diffLines[lineIndex - 1];
utils.startsWith(line, 'diff') || // Git diffs always start with diff var nxtLine = diffLines[lineIndex + 1];
!currentFile || // If we do not have a file yet, we should crete one var afterNxtLine = diffLines[lineIndex + 2];
if (utils.startsWith(line, 'diff')) {
startFile();
currentFile.isGitDiff = true;
return;
}
if (!currentFile || // If we do not have a file yet, we should crete one
( (
currentFile && // If we already have some file in progress and !currentFile.isGitDiff && currentFile && // If we already have some file in progress and
( (
currentFile.oldName && utils.startsWith(line, '--- ') || // Either we reached a old file identification line utils.startsWith(line, oldFileNameHeader) && // If we get to an old file path header line
currentFile.newName && utils.startsWith(line, '+++ ') // Or we reached a new file identification line // And is followed by the new file path header line and the hunk header line
utils.startsWith(nxtLine, newFileNameHeader) && utils.startsWith(afterNxtLine, hunkHeaderPrefix)
) )
) )
) { ) {
@ -2524,6 +2538,19 @@ var Hogan = {};
var values; var values;
/*
* We need to make sure that we have the three lines of the header.
* This avoids cases like the ones described in:
* - https://github.com/rtfpessoa/diff2html/issues/87
*/
if (
(utils.startsWith(line, oldFileNameHeader) &&
utils.startsWith(nxtLine, newFileNameHeader) && utils.startsWith(afterNxtLine, hunkHeaderPrefix)) ||
(utils.startsWith(line, newFileNameHeader) &&
utils.startsWith(prevLine, oldFileNameHeader) && utils.startsWith(nxtLine, hunkHeaderPrefix))
) {
/* /*
* --- Date Timestamp[FractionalSeconds] TimeZone * --- Date Timestamp[FractionalSeconds] TimeZone
* --- 2002-02-21 23:30:39.942229878 -0800 * --- 2002-02-21 23:30:39.942229878 -0800
@ -2546,7 +2573,9 @@ var Hogan = {};
return; return;
} }
if (currentFile && utils.startsWith(line, '@')) { }
if (currentFile && utils.startsWith(line, hunkHeaderPrefix)) {
startBlock(line); startBlock(line);
return; return;
} }
@ -2562,13 +2591,6 @@ var Hogan = {};
return; return;
} }
if (
(currentFile && currentFile.blocks.length) ||
(currentBlock && currentBlock.lines.length)
) {
startFile();
}
/* /*
* Git diffs provide more information regarding files modes, renames, copies, * Git diffs provide more information regarding files modes, renames, copies,
* commits between changes and similarity indexes * commits between changes and similarity indexes
@ -3854,7 +3876,7 @@ module.exports = global.browserTemplates;
return result; return result;
} }
return str.indexOf(start) === 0; return str && str.indexOf(start) === 0;
}; };
Utils.prototype.valueOrEmpty = function(value) { Utils.prototype.valueOrEmpty = function(value) {

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{ {
"name": "diff2html", "name": "diff2html",
"version": "2.0.0-rc.7", "version": "2.0.0-rc.8",
"homepage": "http://rtfpessoa.github.io/diff2html/", "homepage": "http://rtfpessoa.github.io/diff2html/",
"description": "Fast Diff to colorized HTML", "description": "Fast Diff to colorized HTML",
"keywords": [ "keywords": [