diff --git a/package.json b/package.json index d2376bfb6..8b6fddb28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "diff", - "version": "3.5.0", + "version": "3.5.1", "description": "A javascript text diff implementation.", "keywords": [ "diff", diff --git a/src/patch/parse.js b/src/patch/parse.js index d1af8d3dc..dfbaafb04 100755 --- a/src/patch/parse.js +++ b/src/patch/parse.js @@ -18,9 +18,9 @@ export function parsePatch(uniDiff, options = {}) { } // Diff index - let header = (/^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/).exec(line); - if (header) { - index.index = header[1]; + let headerMatch = (/^(?:Index:|diff(?: -r \w+)+)\s+/).exec(line); + if (headerMatch) { + index.index = line.substring(headerMatch[0].length).trim(); } i++; @@ -53,12 +53,12 @@ export function parsePatch(uniDiff, options = {}) { // Parses the --- and +++ headers, if none are found, no lines // are consumed. function parseFileHeader(index) { - const fileHeader = (/^(---|\+\+\+)\s+(.*)$/).exec(diffstr[i]); - if (fileHeader) { - let keyPrefix = fileHeader[1] === '---' ? 'old' : 'new'; - const data = fileHeader[2].split('\t', 2); + const fileHeaderMatch = (/^(---|\+\+\+)\s+/).exec(diffstr[i]); + if (fileHeaderMatch) { + let keyPrefix = fileHeaderMatch[1] === '---' ? 'old' : 'new'; + const data = diffstr[i].substring(3).trim().split('\t', 2); let fileName = data[0].replace(/\\\\/g, '\\'); - if (/^".*"$/.test(fileName)) { + if (fileName.startsWith('"') && fileName.endsWith('"')) { fileName = fileName.substr(1, fileName.length - 2); } index[keyPrefix + 'FileName'] = fileName;