Skip to content

Commit

Permalink
Merge pull request #9027 from sambakk/master
Browse files Browse the repository at this point in the history
Fixes Color.fromCssColorString when color string contains spaces
  • Loading branch information
Hannah authored Jul 21, 2020
2 parents bd9ad36 + acb9e21 commit 37c19e7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

##### Fixes :wrench:

- Fixed `Color.fromCssColorString` when color string contains spaces. [#9015](https://github.com/CesiumGS/cesium/issues/9015)
- Fixed 3D Tileset replacement refinement when leaf is empty. [#8996](https://github.com/CesiumGS/cesium/pull/8996)
- Fixed a bug in the assessment of terrain tile visibility [#9033](https://github.com/CesiumGS/cesium/issues/9033)
- Fixed vertical polylines with `arcType: ArcType.RHUMB`, including lines drawn via GeoJSON. [#9028](https://github.com/CesiumGS/cesium/pull/9028)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Bao Thien Tran](https://github.com/baothientran)
- [Yonatan Kra](https://github.com/yonatankra)
- [Gusain Vipul](https://github.com/vipulgusain)
- [Sam Bakkach](https://github.com/sambakk)
3 changes: 3 additions & 0 deletions Source/Core/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ Color.fromCssColorString = function (color, result) {
result = new Color();
}

// Remove all whitespaces from the color string
color = color.replace(/\s/g, "");

var namedColor = Color[color.toUpperCase()];
if (defined(namedColor)) {
Color.clone(namedColor, result);
Expand Down
13 changes: 13 additions & 0 deletions Specs/Core/ColorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,19 @@ describe("Core/Color", function () {
expect(c).toEqual(Color.LIME);
});

it("fromCssColorString understands the color string even with any number of unnecessary leading, trailing or middle spaces", function () {
expect(Color.fromCssColorString(" rgb( 0, 0, 255)")).toEqual(Color.BLUE);
expect(Color.fromCssColorString("rgb( 255, 255, 255) ")).toEqual(
Color.WHITE
);
expect(Color.fromCssColorString(" #FF0000")).toEqual(Color.RED);
expect(Color.fromCssColorString("#FF0 ")).toEqual(Color.YELLOW);
expect(Color.fromCssColorString(" hsla(720, 100%, 50%, 1.0) ")).toEqual(
Color.RED
);
expect(Color.fromCssColorString("hsl (720, 100%, 50%)")).toEqual(Color.RED);
});

it("fromHsl produces expected output", function () {
expect(Color.fromHsl(0.0, 1.0, 0.5, 1.0)).toEqual(Color.RED);
expect(Color.fromHsl(120.0 / 360.0, 1.0, 0.5, 1.0)).toEqual(Color.LIME);
Expand Down

0 comments on commit 37c19e7

Please sign in to comment.