Skip to content
Open
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
5 changes: 4 additions & 1 deletion sjsonnet/src/sjsonnet/ValVisitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class ValVisitor(pos: Position) extends JsVisitor[Val, Val] { self =>
pos,
if (decIndex != -1 || expIndex != -1) s.toString.toDouble
else if (s.length() == 2 && s.charAt(0) == '-' && s.charAt(1) == '0') -0.0
else upickle.core.ParseUtils.parseIntegralNum(s, decIndex, expIndex, index).toDouble
else {
try upickle.core.ParseUtils.parseIntegralNum(s, decIndex, expIndex, index).toDouble
catch { case _: NumberFormatException => s.toString.toDouble }
}
)

def visitString(s: CharSequence, index: Int): Val = Val.Str(pos, s.toString)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Regression test: std.parseJson must handle integers outside Java long range.
// Verified against cpp-jsonnet 0.21.0, go-jsonnet 0.22.0, jrsonnet 0.5.0-pre99.
// These used to crash with NumberFormatException; now they parse as float64.
std.parseJson("9223372036854775808") > 0 &&
std.parseJson("-9223372036854775809") < 0 &&
std.parseJson("99999999999999999999999999999999") > 0 &&
// Normal integers still work
std.parseJson("42") == 42 &&
std.parseJson("-1") == -1 &&
std.parseJson("0") == 0 &&
std.parseJson("-0") == 0 &&
true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
Loading