Skip to content

Commit a079733

Browse files
committed
make sure we got the right alpha value when parsing from hex
1 parent 3fb1256 commit a079733

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/java/com/gargoylesoftware/css/parser/AbstractCSSParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ else if (len == 4) {
816816
g = (g << 4) | g;
817817
b = (b << 4) | b;
818818
ai = (ai << 4) | ai;
819-
a = ai / 255d;
819+
a = ai / 2.55d;
820820
}
821821
else if (len == 6) {
822822
r = Integer.parseInt(t.image.substring(i + 0, i + 2), 16);
@@ -828,7 +828,7 @@ else if (len == 8) {
828828
g = Integer.parseInt(t.image.substring(i + 2, i + 4), 16);
829829
b = Integer.parseInt(t.image.substring(i + 4, i + 6), 16);
830830
final int ai = Integer.parseInt(t.image.substring(i + 6, i + 8), 16);
831-
a = ai / 255d;
831+
a = ai / 2.55d;
832832
}
833833
else {
834834
final String pattern = getParserMessage("invalidColor");

src/test/java/com/gargoylesoftware/css/parser/CSS3ParserTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,18 @@ public void rgbInsideFunction() throws Exception {
10161016
color("color: foo(rgb(204, 221, 68))", "color: foo(#cd4);");
10171017
}
10181018

1019+
/**
1020+
* @throws Exception in case of failure
1021+
*/
1022+
@Test
1023+
public void hexAndRgbAreSame() throws Exception {
1024+
color("color: rgb(138, 43, 226)", "color: rgb(138,43,226);");
1025+
color("color: rgb(138, 43, 226)", "color: #8A2BE2;");
1026+
1027+
color("color: rgba(138, 43, 226, 80)", "color: rgba(138,43,226, 80);");
1028+
color("color: rgba(138, 43, 226, 80)", "color: #8A2BE2CC;");
1029+
}
1030+
10191031
/**
10201032
* @throws Exception in case of failure
10211033
*/

0 commit comments

Comments
 (0)