Skip to content

Commit

Permalink
Fix fromHex to allow initial #
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealmond committed Jan 24, 2017
1 parent 5d8a633 commit 170ebb1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.0.2 - 2017-01-24

### Fixed
- Allow hex values to include initial #

## 0.0.1 - 2017-01-24

### Added
Expand Down
2 changes: 2 additions & 0 deletions src/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public static function fromCssColor(string $color): Color
*/
private static function hexToRgb(string $color): array
{
$color = ltrim($color, '#');

// Convert the shorthand hex to the full hex (09F => 0099FF)
if (strlen($color) == 3) {
$color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
Expand Down
5 changes: 5 additions & 0 deletions tests/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public function testConvertsToHex()

$color = Color::fromRgb(255, 0, 255);
$this->assertEquals('FF00FF', strval($color));


$this->assertEquals('FF00FF', Color::fromHex('#FF00FF'));

}

/**
Expand Down Expand Up @@ -262,6 +266,7 @@ public function goodHexColors()
['09F'],
['AAABBB'],
['0099FF'],
['#0099FF'],
];
}

Expand Down

0 comments on commit 170ebb1

Please sign in to comment.