Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Rdata/OPT.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null)
$rdLength = $rdLength ?? strlen($rdata);

$endOffset = $offset + $rdLength;
do {
while ($offset < $endOffset) {
$integers = @unpack('ncode/nlength', $rdata, $offset);
if (false === $integers) {
throw new DecodeException(static::TYPE, $rdata);
Expand All @@ -112,6 +112,6 @@ public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null)
}
$option->fromWire($rdata, $offset, $integers['length']);
$this->options[] = $option;
} while ($offset < $endOffset);
}
}
}
10 changes: 10 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ public function testWire8(): void
$this->assertEquals($expectation, $msg->toWire());
}

public function testWire9(): void
{
$expectation = $this->getWireTestData(9);
$msg = Message::fromWire($this->getWireTestData(9));
$additionals = $msg->getAdditionals();
$this->assertCount(1, $additionals);
$this->assertInstanceOf(OPT::class, $additionals[0]->getRdata());
$this->assertEquals($expectation, $msg->toWire());
}

public function testWire10(): void
{
$this->expectException(UnexpectedValueException::class);
Expand Down
9 changes: 9 additions & 0 deletions tests/Rdata/OptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public function testFromWire2(): void
$opt->fromWire($wire);
}

public function testFromWire3(): void
{
$wire = '';

$opt = new OPT();
$opt->fromWire($wire);
$this->assertCount(0, $opt->getOptions());
}

public function testToWire(): void
{
$options = [];
Expand Down
13 changes: 13 additions & 0 deletions tests/Resources/wire/wire_test.data9
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# HEADER SECTION
30 99 # ID
01 20 # FLAGS
00 01 # QDCOUNT=1
00 00 # ANCOUNT=0
00 00 # NSCOUNT=0
00 01 # ARCOUNT=1

#QUESTION SECTION
05 67 6f 6f 67 65 03 63 6f 6d 00 00 01 00 01 # question section: google.com IN A

#ADDITIONAL RECORDS
00 00 29 04 d0 00 00 00 00 00 00
Loading