diff --git a/src/patch/apply.js b/src/patch/apply.js index e830fc11..7bbdb6d0 100644 --- a/src/patch/apply.js +++ b/src/patch/apply.js @@ -34,8 +34,8 @@ export function applyPatch(source, uniDiff, options = {}) { function hunkFits(hunk, toPos) { for (let j = 0; j < hunk.lines.length; j++) { let line = hunk.lines[j], - operation = line[0], - content = line.substr(1); + operation = (line.length > 0 ? line[0] : ' '), + content = (line.length > 0 ? line.substr(1) : line); if (operation === ' ' || operation === '-') { // Context sanity check @@ -91,8 +91,8 @@ export function applyPatch(source, uniDiff, options = {}) { for (let j = 0; j < hunk.lines.length; j++) { let line = hunk.lines[j], - operation = line[0], - content = line.substr(1), + operation = (line.length > 0 ? line[0] : ' '), + content = (line.length > 0 ? line.substr(1) : line), delimiter = hunk.linedelimiters[j]; if (operation === ' ') { diff --git a/src/patch/parse.js b/src/patch/parse.js index 310e3a94..6300171e 100755 --- a/src/patch/parse.js +++ b/src/patch/parse.js @@ -95,7 +95,7 @@ export function parsePatch(uniDiff, options = {}) { && diffstr[i + 2].indexOf('@@') === 0) { break; } - let operation = diffstr[i][0]; + let operation = (diffstr[i].length == 0 && i != (diffstr.length - 1)) ? ' ' : diffstr[i][0]; if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') { hunk.lines.push(diffstr[i]);