Fix filename parsing on filenames with tabs

* Why would someone create files with tabs?
This commit is contained in:
Rodrigo Fernandes 2016-02-23 21:40:56 +00:00
parent 64c1e827b7
commit 9205e5e0a1
3 changed files with 20 additions and 8 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "diff2html", "name": "diff2html",
"version": "2.0.0-beta2", "version": "2.0.0-beta3",
"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": [

View file

@ -1,6 +1,6 @@
{ {
"name": "diff2html", "name": "diff2html",
"version": "2.0.0-beta2", "version": "2.0.0-beta3",
"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": [

View file

@ -161,10 +161,10 @@
if (utils.startsWith(line, 'diff')) { if (utils.startsWith(line, 'diff')) {
startFile(); startFile();
} else if (currentFile && !currentFile.oldName && (values = getSrcFilename(line, config))) { } else if (currentFile && !currentFile.oldName && (values = getSrcFilename(line, config))) {
currentFile.oldName = values[1]; currentFile.oldName = values;
currentFile.language = getExtension(currentFile.oldName, currentFile.language); currentFile.language = getExtension(currentFile.oldName, currentFile.language);
} else if (currentFile && !currentFile.newName && (values = getDstFilename(line, config))) { } else if (currentFile && !currentFile.newName && (values = getDstFilename(line, config))) {
currentFile.newName = values[1]; currentFile.newName = values;
currentFile.language = getExtension(currentFile.newName, currentFile.language); currentFile.language = getExtension(currentFile.newName, currentFile.language);
} else if (currentFile && utils.startsWith(line, '@@')) { } else if (currentFile && utils.startsWith(line, '@@')) {
startBlock(line); startBlock(line);
@ -227,7 +227,7 @@
} }
function getSrcFilename(line, cfg) { function getSrcFilename(line, cfg) {
var prefixes = ["a\\/", "i\\/", "w\\/", "c\\/", "o\\/"]; var prefixes = ["a/", "i/", "w/", "c/", "o/"];
if (cfg.srcPrefix) prefixes.push(cfg.srcPrefix); if (cfg.srcPrefix) prefixes.push(cfg.srcPrefix);
@ -235,7 +235,7 @@
} }
function getDstFilename(line, cfg) { function getDstFilename(line, cfg) {
var prefixes = ["b\\/", "i\\/", "w\\/", "c\\/", "o\\/"]; var prefixes = ["b/", "i/", "w/", "c/", "o/"];
if (cfg.dstPrefix) prefixes.push(cfg.dstPrefix); if (cfg.dstPrefix) prefixes.push(cfg.dstPrefix);
@ -243,8 +243,20 @@
} }
function _getFilename(linePrefix, line, prefixes) { function _getFilename(linePrefix, line, prefixes) {
var prefixesStr = prefixes.join("|"); var FilenameRegExp = new RegExp('^' + linePrefix + ' "?(.+?)"?$');
return new RegExp('^' + linePrefix + ' "?(?:' + prefixesStr + ')(.+?)"?$').exec(line);
var filename;
var values = FilenameRegExp.exec(line);
if (values && values[1]) {
filename = values[1];
var prefix = prefixes.find(function(prefix) {
return filename.startsWith(prefix);
});
if (prefix) filename = filename.slice(prefix.length); // remove prefix if exists
}
return filename;
} }
module.exports.DiffParser = new DiffParser(); module.exports.DiffParser = new DiffParser();