From 6555570ab158d230957ceb0720d0d70285c32f92 Mon Sep 17 00:00:00 2001 From: William Storey Date: Wed, 7 Jan 2026 09:08:12 -0800 Subject: [PATCH 1/2] Add changelog entry for #290 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b97b4413..aa00c8f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ CHANGELOG ========= +3.3.1 (unreleased) +------------------ + +* Updated the `GeoIp2\Model\City` constructor to handle an empty + `subdivisions` array. This provides compatibility with some third-party + databases that publish empty subdivisions arrays. Pull request by Jarek + Jakubowski. GitHub #290. + 3.3.0 (2025-11-20) ------------------ From 5f18a4aad407edc12775f9819437c8c3d1d2127a Mon Sep 17 00:00:00 2001 From: William Storey Date: Wed, 7 Jan 2026 09:11:04 -0800 Subject: [PATCH 2/2] Add test for empty subdivisions array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- tests/GeoIp2/Test/Model/InsightsTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/GeoIp2/Test/Model/InsightsTest.php b/tests/GeoIp2/Test/Model/InsightsTest.php index f2cb9f68..195623b9 100644 --- a/tests/GeoIp2/Test/Model/InsightsTest.php +++ b/tests/GeoIp2/Test/Model/InsightsTest.php @@ -497,4 +497,24 @@ public function testMostSpecificSubdivisionWithNoSubdivisions(): void 'mostSpecificSubdivision is set even on an empty response' ); } + + // We do not expect well-formed databases from MaxMind to have empty + // subdivisions arrays, but we support it due to encountering a third-party + // database that had them. + public function testEmptySubdivisionsArray(): void + { + $raw = [ + 'subdivisions' => [], + 'traits' => ['ip_address' => '1.1.1.1'], + ]; + + $model = new Insights($raw, ['en']); + + $this->assertCount(0, $model->subdivisions); + + $this->assertInstanceOf( + 'GeoIp2\Record\Subdivision', + $model->mostSpecificSubdivision + ); + } }