mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 12:55:26 +01:00
Add range check
This commit is contained in:
parent
bf569d1b07
commit
a1ca7ac4a4
@ -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