Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: prevent meaningless ratio calculation for zero height in EmbedCode
  • Loading branch information
uzulla committed Oct 6, 2025
commit c128a80ea019958d151003ffd3d62233b766926a
2 changes: 1 addition & 1 deletion src/EmbedCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(string $html, ?int $width = null, ?int $height = nul
$this->width = $width;
$this->height = $height;

if ($width !== null && $width !== 0 && $height !== null) {
if ($width !== null && $width !== 0 && $height !== null && $height !== 0) {
$this->ratio = round(($height / $width) * 100, 3);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/EmbedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function testRatioCalculationWithNullHeight()

public function testRatioCalculationWithZeroHeight()
{
// height=0 case (ratio becomes 0.0)
// height=0 case (prevents meaningless ratio calculation)
$code = new EmbedCode('<iframe></iframe>', 400, 0);
$this->assertEquals(0.0, $code->ratio);
$this->assertNull($code->ratio);
}

public function testRatioCalculationWithBothZero()
Expand Down