From e34f2d1f5c6b0afe0b26cdcba545a129a1db5142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20Biri=C8=99an?= <6582802+razvbir@users.noreply.github.com> Date: Fri, 13 Mar 2026 14:23:11 +0200 Subject: [PATCH 1/6] Fix #221: Throw `LogicException` in `Tag::id()` when id is empty string --- CHANGELOG.md | 1 + src/Tag/Base/Tag.php | 7 ++++++- tests/Tag/Base/TagTest.php | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e291fb7..789e268f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Enh #261: Enhance `RadioList::addRadioWrapClass()` method for cleaner class addition (@vjik) - Enh #263: Explicitly import classes and constants in "use" section (@mspirkov) - Chg #243: Deprecate static constructors such as `TagName::tag()` in favor of `new TagName()` (@razvbir) +- Chg #221: Throw `LogicException` in `Tag::id()` when id is empty string (@razvbir) ## 3.12.0 December 13, 2025 diff --git a/src/Tag/Base/Tag.php b/src/Tag/Base/Tag.php index 942da0eb..f8dc389c 100644 --- a/src/Tag/Base/Tag.php +++ b/src/Tag/Base/Tag.php @@ -5,6 +5,7 @@ namespace Yiisoft\Html\Tag\Base; use BackedEnum; +use LogicException; use Yiisoft\Html\Html; use Yiisoft\Html\NoEncodeStringableInterface; @@ -75,10 +76,14 @@ final public function attribute(string $name, mixed $value): static * * @param string|null $id Tag ID. * - * @psalm-param non-empty-string|null $id + * @throws LogicException */ final public function id(?string $id): static { + if ($id === '') { + throw new LogicException('The tag id cannot be an empty string.'); + } + $new = clone $this; $new->attributes['id'] = $id; return $new; diff --git a/tests/Tag/Base/TagTest.php b/tests/Tag/Base/TagTest.php index e0a3416f..62ca4310 100644 --- a/tests/Tag/Base/TagTest.php +++ b/tests/Tag/Base/TagTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\Html\Tests\Tag\Base; +use LogicException; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Yiisoft\Html\Tests\Objects\TestTag; @@ -132,6 +133,13 @@ public function testId(string $expected, ?string $id): void $this->assertSame($expected, (string) (new TestTag())->id($id)); } + public function testIdEmptyString(): void + { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('The tag id cannot be an empty string.'); + (new TestTag())->id(''); + } + public static function dataAddClass(): array { return [ From df9e6dd894bca8b876f4ea102647adc00a6b607c Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 13 Mar 2026 17:11:21 +0300 Subject: [PATCH 2/6] changelog and upgrade --- CHANGELOG.md | 3 +-- UPGRADE.md | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 UPGRADE.md diff --git a/CHANGELOG.md b/CHANGELOG.md index d1246d76..8bc4437b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 3.13.1 under development -- no changes in this release. +- Chg #221: Throw `LogicException` in `Tag::id()` when id is empty string (@razvbir) ## 3.13.0 March 13, 2026 @@ -11,7 +11,6 @@ - Enh #261: Enhance `RadioList::addRadioWrapClass()` method for cleaner class addition (@vjik) - Enh #263: Explicitly import classes and constants in "use" section (@mspirkov) - Chg #243: Deprecate static constructors such as `TagName::tag()` in favor of `new TagName()` (@razvbir) -- Chg #221: Throw `LogicException` in `Tag::id()` when id is empty string (@razvbir) ## 3.12.0 December 13, 2025 diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 00000000..37b8a9f6 --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,13 @@ +# Upgrading Instructions for Yii HTML + +This file contains the upgrade notes. These notes highlight changes that could break your +application when you upgrade the package from one version to another. + +> **Important!** The following upgrading instructions are cumulative. That is, if you want +> to upgrade from version A to version C and there is version B between A and C, you need +> to follow the instructions for both A and B. + +## Upgrade from 3.x + +- `Tag::id()` now throws `LogicException` when an empty string is passed. Check your code for places where you call + `Tag::id()` and make sure you are not passing an empty string. From 45651a17ca0ff2f7a0eeea21bc8c32cc9209c481 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 13 Mar 2026 17:12:03 +0300 Subject: [PATCH 3/6] fix --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc4437b..4de229b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,6 @@ - Chg #243: Deprecate static constructors such as `TagName::tag()` in favor of `new TagName()` (@razvbir) - Enh #261: Enhance `RadioList::addRadioWrapClass()` method for cleaner class addition (@vjik) - Enh #263: Explicitly import classes and constants in "use" section (@mspirkov) -- Chg #243: Deprecate static constructors such as `TagName::tag()` in favor of `new TagName()` (@razvbir) ## 3.12.0 December 13, 2025 From 6bff0addb2a58c48f7ac99aa44fd5f8d12d6d0cf Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 13 Mar 2026 17:12:37 +0300 Subject: [PATCH 4/6] fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4de229b4..3fb516a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Yii HTML Change Log -## 3.13.1 under development +## 4.0.0 under development - Chg #221: Throw `LogicException` in `Tag::id()` when id is empty string (@razvbir) From b6cb1380e1202239313036d0586b20c701dfac6a Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 13 Mar 2026 17:14:22 +0300 Subject: [PATCH 5/6] fix --- src/Tag/Base/Tag.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tag/Base/Tag.php b/src/Tag/Base/Tag.php index f8dc389c..d529883d 100644 --- a/src/Tag/Base/Tag.php +++ b/src/Tag/Base/Tag.php @@ -74,9 +74,9 @@ final public function attribute(string $name, mixed $value): static /** * Set tag ID. * - * @param string|null $id Tag ID. + * @param string|null $id Non-empty tag ID. * - * @throws LogicException + * @psalm-param non-empty-string|null $id */ final public function id(?string $id): static { From 56e83065ed36bb7af62d88673e1d6277ecdd26e0 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 13 Mar 2026 17:15:45 +0300 Subject: [PATCH 6/6] fix --- src/Tag/Base/Tag.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tag/Base/Tag.php b/src/Tag/Base/Tag.php index d529883d..ee4d8f8b 100644 --- a/src/Tag/Base/Tag.php +++ b/src/Tag/Base/Tag.php @@ -80,6 +80,7 @@ final public function attribute(string $name, mixed $value): static */ final public function id(?string $id): static { + /** @psalm-suppress TypeDoesNotContainType */ if ($id === '') { throw new LogicException('The tag id cannot be an empty string.'); }