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 9a338cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21657,6 +21657,8 @@ class Git {
return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => {
const lines = fileDiff.split('\n')
const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++'))
if (lastHeaderLineIndex === -1) return resultDict // ignore binary files

const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim()
let filePath = ''
if (lines[lastHeaderLineIndex].startsWith('+++ b/')) { // every file except removed files
Expand Down
2 changes: 2 additions & 0 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class Git {
return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => {
const lines = fileDiff.split('\n')
const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++'))
if (lastHeaderLineIndex === -1) return resultDict // ignore binary files

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 9a338cb

Please sign in to comment.