Skip to content

Commit

Permalink
FIX off-by-one error when gitignore file is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
snim2 committed Nov 26, 2023
1 parent 60e74aa commit c2137a7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Git/Gitignore.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function save_ignores($ignores)
private function ensure_closing_newline($ignores)
{
$index_of_last_line = count($ignores) - 1;
$last_line = $ignores[$index_of_last_line];
$last_line = $index_of_last_line >= 0 ? $ignores[$index_of_last_line] : 0;
$last_character = substr($last_line, -1);

if ($last_character != "\n") {
Expand Down

0 comments on commit c2137a7

Please sign in to comment.