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
10 changes: 8 additions & 2 deletions src/Cloudinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,14 @@ private static function split_range($range)

private static function norm_range_value($value)
{
if (empty($value)) {
return null;
if (is_null($value)) {
return null;
}

// Ensure that trailing decimal(.0) part is not cropped when float is provided
// e.g. float 1.0 should be returned as "1.0" and not "1" as it happens by default
if (is_float($value) && $value - (int)$value == 0) {
$value = sprintf("%.1f", $value);
}

preg_match(Cloudinary::RANGE_VALUE_RE, $value, $matches);
Expand Down
11 changes: 11 additions & 0 deletions tests/CloudinaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,13 +968,24 @@ public function test_norm_range_value()
$method->setAccessible(true);
// should parse integer range values
$this->assertEquals($method->invoke(null, "200"), "200");
$this->assertEquals($method->invoke(null, 200), "200");
$this->assertEquals($method->invoke(null, 0), "0");
// should parse float range values
$this->assertEquals($method->invoke(null, "200.0"), "200.0");
$this->assertEquals($method->invoke(null, 200.0), "200.0");
$this->assertEquals($method->invoke(null, 200.00), "200.0");
$this->assertEquals($method->invoke(null, 200.123), "200.123");
$this->assertEquals($method->invoke(null, 200.123000), "200.123");
$this->assertEquals($method->invoke(null, 0.0), "0.0");
// should parse a percent range value
$this->assertEquals($method->invoke(null, "20p"), "20p");
$this->assertEquals($method->invoke(null, "20P"), "20p");
$this->assertEquals($method->invoke(null, "20%"), "20p");
$this->assertEquals($method->invoke(null, "20.5%"), "20.5p");
// should handle invalid input
$this->assertNull($method->invoke(null, "p"));
$this->assertNull($method->invoke(null, ""));
$this->assertNull($method->invoke(null, null));
}

public function test_video_codec()
Expand Down