1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix #4603 - fix arithmetic to prevent end column 0

This commit is contained in:
Matt Brown 2020-11-18 13:19:54 -05:00 committed by Daniil Gentili
parent a48f686695
commit e1c3959f5a
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7

View File

@ -308,13 +308,17 @@ class CodeLocation
$newlines = substr_count($this->text, "\n");
if ($newlines) {
$this->column_to = $this->selection_end -
(int)strrpos($file_contents, "\n", $this->selection_end - strlen($file_contents));
$last_newline_pos = strrpos($file_contents, "\n", $this->selection_end - strlen($file_contents) - 1);
$this->column_to = $this->selection_end - (int)$last_newline_pos;
} else {
$this->column_to = $this->column_from + strlen($this->text);
}
$this->end_line_number = $this->getLineNumber() + $newlines;
if ($this->column_to === 0) {
throw new \UnexpectedValueException('bad');
}
}
public function getLineNumber(): int