Skip to content

Commit

Permalink
Don't crash while trying to parse a diff for binary files, fix BetaHu…
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Aug 23, 2022
1 parent e84bc1e commit 10354a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21656,7 +21656,9 @@ 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')
const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++'))
if (lines.length === 0) return resultDict; // ignore binary files

const lastHeaderLineIndex = lines.findIndex((line) => line && line.startsWith('+++'))
const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim()
let filePath = ''
if (lines[lastHeaderLineIndex].startsWith('+++ b/')) { // every file except removed files
Expand Down
4 changes: 3 additions & 1 deletion src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ 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')
const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++'))
if (lines.length === 0) return resultDict; // ignore binary files

const lastHeaderLineIndex = lines.findIndex((line) => line && line.startsWith('+++'))
const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim()
let filePath = ''
if (lines[lastHeaderLineIndex].startsWith('+++ b/')) { // every file except removed files
Expand Down

0 comments on commit 10354a8

Please sign in to comment.