Skip to content

Commit

Permalink
Handles Long overflow on JsonTypeCoercer (#7423)
Browse files Browse the repository at this point in the history
Ensures that if a value is an integer, it can be safely casted to Long. Otherwise, it returns a Double.

Fixes #7398
  • Loading branch information
albertor24 authored and shs96c committed Aug 1, 2019
1 parent 85a1010 commit 9c9661f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions java/client/src/org/openqa/selenium/json/JsonTypeCoercer.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ private JsonTypeCoercer(Stream<TypeCoercer<?>> coercers) {
new NumberCoercer<>(
Number.class,
num -> {
if (num.doubleValue() % 1 != 0) {
return num.doubleValue();
Double doubleValue = num.doubleValue();
if (doubleValue % 1 != 0 || doubleValue > Long.MAX_VALUE) {
return doubleValue;
}
return num.longValue();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ public void testPassingAndReturningALongShouldReturnAWholeNumber() {
assertThat(result).isInstanceOfAny(Integer.class, Long.class).isEqualTo(expectedResult);
}

@Test
public void testReturningOverflownLongShouldReturnADouble() {
driver.get(pages.javascriptPage);
Double expectedResult = 6.02214129e+23;
Object result = executeScript("return arguments[0];", expectedResult);
assertThat(result).isInstanceOf(Double.class).isEqualTo(expectedResult);
}

@Test
public void testPassingAndReturningADoubleShouldReturnADecimal() {
driver.get(pages.javascriptPage);
Expand Down

0 comments on commit 9c9661f

Please sign in to comment.