From 8d7187d4324b9bba30cbde68fef75e00c048d28a Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Wed, 16 Sep 2026 14:19:07 +0200 Subject: [PATCH] =?UTF-8?q?bugfix(multi):=20=F0=9F=90=9B=20keep=20the=20ex?= =?UTF-8?q?plicit=20strategy=20on=20Multi::fromEmbedded()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The inherited IPv6 implementation rebuilt the instance without the strategy, so a non-default strategy packed the address but the result reported as version 6. --- CHANGELOG.md | 1 + docs/04-helpers.md | 1 + src/Version/Multi.php | 10 ++++++++++ tests/Version/MultiTest.php | 9 +++++++++ 4 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2f2a9d..5198dd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ - Add `fromInteger()` and `tryFromInteger()` on the new `Contracts\Factory4Interface` (IPv4 and Multi). - Arbitrary-precision `fromIntegerString()` and `tryFromIntegerString()` on all classes. - Fix: `Multi::fromProtocol()` now rejects a binary string of the wrong length instead of passing it through. +- Fix: `Multi::fromEmbedded()` now keeps the strategy it is given instead of falling back to the default. ### Output diff --git a/docs/04-helpers.md b/docs/04-helpers.md index 798154b..3a7f34e 100644 --- a/docs/04-helpers.md +++ b/docs/04-helpers.md @@ -228,6 +228,7 @@ an IPv6 address. ```php assertSame('2002:0c22:384e:0000:0000:0000:0000:0000', $ip->toExpandedAddress()); } + /** @test */ + #[PHPUnit\Test] + public function testFromEmbeddedUsesExplicitStrategy(): void + { + $ip = IP::fromEmbedded('127.0.0.1', new Strategy\Derived()); + $this->assertSame('2002:7f00:1::', $ip->toCompactedAddress()); + $this->assertSame('127.0.0.1', $ip->toDotAddress()); + } + /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getValidBinarySequences()