mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Add range check
This commit is contained in:
parent
5b140bf522
commit
1025b29e06
@ -23,7 +23,7 @@ class FileManipulation
|
||||
|
||||
/** @var bool */
|
||||
public $remove_trailing_newline;
|
||||
|
||||
|
||||
public function __construct(
|
||||
int $start,
|
||||
int $end,
|
||||
@ -59,7 +59,10 @@ class FileManipulation
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->remove_trailing_newline && $existing_contents[$this->end] === "\n") {
|
||||
if ($this->remove_trailing_newline
|
||||
&& strlen($existing_contents) > $this->end
|
||||
&& $existing_contents[$this->end] === "\n"
|
||||
) {
|
||||
$newline_pos = strrpos($existing_contents, "\n", $this->start - strlen($existing_contents));
|
||||
|
||||
$newline_pos = $newline_pos !== false ? $newline_pos + 1 : 0;
|
||||
|
Loading…
Reference in New Issue
Block a user