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 e950b5b
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 @@ -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 = ''
Expand Down
2 changes: 2 additions & 0 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down

0 comments on commit e950b5b

Please sign in to comment.