Merge pull request #143 from romellem/fix-timestamp-strip

Fix regex to strip timestamp when timezone is behind GMT
This commit is contained in:
Rodrigo Fernandes 2017-10-09 21:19:22 +01:00 committed by GitHub
commit 1b0af44179
2 changed files with 30 additions and 19 deletions

View file

@ -435,7 +435,7 @@
// Cleanup timestamps generated by the unified diff (diff command) as specified in // Cleanup timestamps generated by the unified diff (diff command) as specified in
// https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html // https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html
// Ie: 2016-10-25 11:37:14.000000000 +0200 // 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; return filename;

View file

@ -400,14 +400,24 @@ describe('DiffParser', function() {
}); });
it('should parse unified non git diff and strip timestamps off the headers', function() { it('should parse unified non git diff and strip timestamps off the headers', function() {
var diff = var diffs = [
// 2 hours ahead of GMT
'--- a/sample.js 2016-10-25 11:37:14.000000000 +0200\n' + '--- a/sample.js 2016-10-25 11:37:14.000000000 +0200\n' +
'+++ b/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' + '@@ -1 +1,2 @@\n' +
'-test\n' + '-test\n' +
'+test1r\n' + '+test1r\n' +
'+test2r\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'
];
diffs.forEach(function(diff) {
var result = DiffParser.generateDiffJson(diff); var result = DiffParser.generateDiffJson(diff);
var file1 = result[0]; var file1 = result[0];
assert.equal(1, result.length); assert.equal(1, result.length);
@ -422,6 +432,7 @@ describe('DiffParser', function() {
}); });
assert.deepEqual(linesContent, ['-test', '+test1r', '+test2r']); assert.deepEqual(linesContent, ['-test', '+test1r', '+test2r']);
}); });
});
it('should parse unified non git diff', function() { it('should parse unified non git diff', function() {
var diff = var diff =