diff --git a/src/diff-parser.js b/src/diff-parser.js index 4f3fdf6..57892cb 100644 --- a/src/diff-parser.js +++ b/src/diff-parser.js @@ -435,7 +435,7 @@ // Cleanup timestamps generated by the unified diff (diff command) as specified in // https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html // Ie: 2016-10-25 11:37:14.000000000 +0200 - filename = filename.replace(/\s+\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)? \+\d{4}.*$/, ''); + filename = filename.replace(/\s+\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)? [-+]\d{4}.*$/, ''); } return filename; diff --git a/test/diff-parser-tests.js b/test/diff-parser-tests.js index b910868..2574c19 100644 --- a/test/diff-parser-tests.js +++ b/test/diff-parser-tests.js @@ -400,27 +400,38 @@ describe('DiffParser', function() { }); it('should parse unified non git diff and strip timestamps off the headers', function() { - var diff = - '--- a/sample.js 2016-10-25 11:37:14.000000000 +0200\n' + - '+++ b/sample.js 2016-10-25 11:37:14.000000000 +0200\n' + - '@@ -1 +1,2 @@\n' + - '-test\n' + - '+test1r\n' + - '+test2r\n'; + var diffs = [ + // 2 hours ahead of GMT + '--- a/sample.js 2016-10-25 11:37:14.000000000 +0200\n' + + '+++ b/sample.js 2016-10-25 11:37:14.000000000 +0200\n' + + '@@ -1 +1,2 @@\n' + + '-test\n' + + '+test1r\n' + + '+test2r\n', + // 2 hours behind GMT + '--- a/sample.js 2016-10-25 11:37:14.000000000 -0200\n' + + '+++ b/sample.js 2016-10-25 11:37:14.000000000 -0200\n' + + '@@ -1 +1,2 @@\n' + + '-test\n' + + '+test1r\n' + + '+test2r\n' + ]; - var result = DiffParser.generateDiffJson(diff); - var file1 = result[0]; - assert.equal(1, result.length); - assert.equal(2, file1.addedLines); - assert.equal(1, file1.deletedLines); - assert.equal('sample.js', file1.oldName); - assert.equal('sample.js', file1.newName); - assert.equal(1, file1.blocks.length); + diffs.forEach(function(diff) { + var result = DiffParser.generateDiffJson(diff); + var file1 = result[0]; + assert.equal(1, result.length); + assert.equal(2, file1.addedLines); + assert.equal(1, file1.deletedLines); + assert.equal('sample.js', file1.oldName); + assert.equal('sample.js', file1.newName); + assert.equal(1, file1.blocks.length); - var linesContent = file1.blocks[0].lines.map(function(line) { - return line.content; + var linesContent = file1.blocks[0].lines.map(function(line) { + return line.content; + }); + assert.deepEqual(linesContent, ['-test', '+test1r', '+test2r']); }); - assert.deepEqual(linesContent, ['-test', '+test1r', '+test2r']); }); it('should parse unified non git diff', function() {