Have get_arg never return null
90% of places assume it will never return null, and they will break in weird ways if it does return null
This commit is contained in:
@ -106,13 +106,28 @@ class PageRequestEvent extends Event
|
||||
/**
|
||||
* Get the n th argument of the page request (if it exists.)
|
||||
*/
|
||||
public function get_arg(int $n): ?string
|
||||
public function get_arg(int $n): string
|
||||
{
|
||||
$offset = $this->part_count + $n;
|
||||
if ($offset >= 0 && $offset < $this->arg_count) {
|
||||
return $this->args[$offset];
|
||||
} else {
|
||||
return null;
|
||||
throw new SCoreException("Requested an invalid argument #$n");
|
||||
}
|
||||
}
|
||||
|
||||
public function try_page_num(int $n): int {
|
||||
if($this->count_args() > $n) {
|
||||
$i = $this->get_arg($n);
|
||||
if (!is_numeric($i) || $i <= 0) {
|
||||
return int_escape($i);
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user