1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00

utf8 validate header strings

This commit is contained in:
Robin Appelman 2022-05-24 13:40:45 +02:00
commit 7f10029cf4
2 changed files with 22 additions and 6 deletions

View file

@ -18,7 +18,7 @@ class Header {
protected float $duration; protected float $duration;
protected int $ticks; protected int $ticks;
protected int $frames; protected int $frames;
protected int $singOn; protected int $signOn;
public function __construct( public function __construct(
string $type, string $type,
@ -31,8 +31,24 @@ class Header {
float $duration, float $duration,
int $ticks, int $ticks,
int $frames, int $frames,
int $sigon int $signOn
) { ) {
if (!mb_check_encoding($type, 'UTF-8')) {
$type = '--';
}
if (!mb_check_encoding($server, 'UTF-8')) {
$server = '--';
}
if (!mb_check_encoding($nick, 'UTF-8')) {
$nick = '--';
}
if (!mb_check_encoding($map, 'UTF-8')) {
$map = '--';
}
if (!mb_check_encoding($game, 'UTF-8')) {
$game = '--';
}
$this->type = $type; $this->type = $type;
$this->version = $version; $this->version = $version;
$this->protocol = $protocol; $this->protocol = $protocol;
@ -43,7 +59,7 @@ class Header {
$this->duration = $duration; $this->duration = $duration;
$this->ticks = $ticks; $this->ticks = $ticks;
$this->frames = $frames; $this->frames = $frames;
$this->singOn = $sigon; $this->signOn = $signOn;
} }
public function getDuration(): float { public function getDuration(): float {
@ -74,8 +90,8 @@ class Header {
return $this->server; return $this->server;
} }
public function getSingOn(): int { public function getSignOn(): int {
return $this->singOn; return $this->signOn;
} }
public function getTicks(): int { public function getTicks(): int {

View file

@ -36,7 +36,7 @@ class HeaderParserTest extends TestCase {
$this->assertEquals($expected->getMap(), $parsed->getMap()); $this->assertEquals($expected->getMap(), $parsed->getMap());
$this->assertEquals($expected->getNick(), $parsed->getNick()); $this->assertEquals($expected->getNick(), $parsed->getNick());
$this->assertEquals($expected->getProtocol(), $parsed->getProtocol()); $this->assertEquals($expected->getProtocol(), $parsed->getProtocol());
$this->assertEquals($expected->getSingOn(), $parsed->getSingOn()); $this->assertEquals($expected->getSignOn(), $parsed->getSignOn());
$this->assertEquals($expected->getType(), $parsed->getType()); $this->assertEquals($expected->getType(), $parsed->getType());
$this->assertEquals($expected->getVersion(), $parsed->getVersion()); $this->assertEquals($expected->getVersion(), $parsed->getVersion());
} }