Fix parsing of binary files

This commit is contained in:
Rodrigo Fernandes 2016-07-12 16:17:20 +01:00
parent 2f53bf777e
commit 9bbc87ae89
No known key found for this signature in database
GPG key ID: 08E3C5F38969078E
3 changed files with 27 additions and 4 deletions

View file

@ -39,7 +39,7 @@
"release": "./scripts/release.sh",
"release-bower": "./scripts/update-bower-version.sh",
"templates": "./scripts/hulk.js --wrapper node --variable 'browserTemplates' ./src/templates/*.mustache > ./src/templates/diff2html-templates.js",
"style": "jscs src/*.js src/ui/js/*.js",
"style": "eslint src/*.js src/ui/js/*.js",
"coverage": "istanbul cover _mocha -- -u exports -R spec ./test/**/*",
"check-coverage": "istanbul check-coverage --statements 90 --functions 90 --branches 85 --lines 90 ./coverage/coverage.json",
"test": "npm run style && npm run coverage && npm run check-coverage",

View file

@ -211,10 +211,10 @@
*/
if (
(utils.startsWith(line, oldFileNameHeader) &&
utils.startsWith(nxtLine, newFileNameHeader) && utils.startsWith(afterNxtLine, hunkHeaderPrefix)) ||
utils.startsWith(nxtLine, newFileNameHeader)) ||
(utils.startsWith(line, newFileNameHeader) &&
utils.startsWith(prevLine, oldFileNameHeader) && utils.startsWith(nxtLine, hunkHeaderPrefix))
utils.startsWith(prevLine, oldFileNameHeader))
) {
/*
* --- Date Timestamp[FractionalSeconds] TimeZone
@ -239,7 +239,10 @@
}
}
if (currentFile && utils.startsWith(line, hunkHeaderPrefix)) {
if (
(currentFile && utils.startsWith(line, hunkHeaderPrefix)) ||
(currentFile.isGitDiff && currentFile && currentFile.oldName && currentFile.newName && !currentBlock)
) {
startBlock(line);
return;
}

View file

@ -523,5 +523,25 @@ describe('DiffParser', function() {
assert.deepEqual(linesContent, [' test']);
});
it('should parse binary file diff', function() {
var diff =
'diff --git a/last-changes-config.png b/last-changes-config.png\n' +
'index 322248b..56fc1f2 100644\n' +
'--- a/last-changes-config.png\n' +
'+++ b/last-changes-config.png\n' +
'Binary files differ';
var result = DiffParser.generateDiffJson(diff);
var file1 = result[0];
assert.equal(1, result.length);
assert.equal(0, file1.addedLines);
assert.equal(0, file1.deletedLines);
assert.equal('last-changes-config.png', file1.oldName);
assert.equal('last-changes-config.png', file1.newName);
assert.equal(1, file1.blocks.length);
assert.equal(0, file1.blocks[0].lines.length);
assert.equal('Binary files differ', file1.blocks[0].header);
});
});
});