🐛 Don't crash while trying to parse a diff for binary files, fix #128 (#242)

This commit is contained in:
exAspArk 2022-08-24 04:24:29 -04:00 committed by GitHub
parent e84bc1e894
commit ca2043bbbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

2
dist/index.js vendored
View File

@ -21657,6 +21657,8 @@ class Git {
return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => { return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => {
const lines = fileDiff.split('\n') const lines = fileDiff.split('\n')
const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++')) const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++'))
if (lastHeaderLineIndex === -1) return resultDict // ignore binary files
const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim() const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim()
let filePath = '' let filePath = ''
if (lines[lastHeaderLineIndex].startsWith('+++ b/')) { // every file except removed files if (lines[lastHeaderLineIndex].startsWith('+++ b/')) { // every file except removed files

View File

@ -160,6 +160,8 @@ class Git {
return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => { return `\n${ string }`.split('\ndiff --git').slice(1).reduce((resultDict, fileDiff) => {
const lines = fileDiff.split('\n') const lines = fileDiff.split('\n')
const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++')) const lastHeaderLineIndex = lines.findIndex((line) => line.startsWith('+++'))
if (lastHeaderLineIndex === -1) return resultDict // ignore binary files
const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim() const plainDiff = lines.slice(lastHeaderLineIndex + 1).join('\n').trim()
let filePath = '' let filePath = ''
if (lines[lastHeaderLineIndex].startsWith('+++ b/')) { // every file except removed files if (lines[lastHeaderLineIndex].startsWith('+++ b/')) { // every file except removed files