From e950b5bc0dd469e769b33c0fab136a89dad2a9f2 Mon Sep 17 00:00:00 2001 From: exAspArk Date: Mon, 22 Aug 2022 16:34:17 -0400 Subject: [PATCH] Don't crash while trying to parse a diff for binary files, fix #128 --- dist/index.js | 2 ++ src/git.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dist/index.js b/dist/index.js index 5ea94232..fa282628 100644 --- a/dist/index.js +++ b/dist/index.js @@ -21656,6 +21656,8 @@ class Git { // split diff into separate entries for separate files. \ndiff --git should be a reliable way to detect the separation, as content of files is always indented return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => { const lines = fileDiff.split('\n') + if (lines.length === 0) return resultDict; // ignore binary files + const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++')) const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim() let filePath = '' diff --git a/src/git.js b/src/git.js index e7c0cdf1..1911bd99 100644 --- a/src/git.js +++ b/src/git.js @@ -159,6 +159,8 @@ class Git { // split diff into separate entries for separate files. \ndiff --git should be a reliable way to detect the separation, as content of files is always indented return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => { const lines = fileDiff.split('\n') + if (lines.length === 0) return resultDict; // ignore binary files + const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++')) const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim() let filePath = ''