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
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
### CLI

### Bundles
* Fix float precision loss when parsing number-type template variables during `bundle init` (denik/random-bugfixes-3)

### Dependency updates
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"properties": {
"n": {
"type": "number",
"description": "A number variable",
"default": 1.1
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

>>> [CLI] bundle init .
✨ Successfully initialized template

>>> cat number.txt
n: 1.1
4 changes: 4 additions & 0 deletions acceptance/bundle/templates-machinery/number-precision/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trace $CLI bundle init .

trace cat number.txt
rm number.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
n: {{ .n }}
2 changes: 1 addition & 1 deletion libs/jsonschema/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func fromString(s string, T Type) (any, error) {
case BooleanType:
v, err = strconv.ParseBool(s)
case NumberType:
v, err = strconv.ParseFloat(s, 32)
v, err = strconv.ParseFloat(s, 64)
case IntegerType:
v, err = strconv.ParseInt(s, 10, 64)
case ArrayType, ObjectType:
Expand Down
5 changes: 2 additions & 3 deletions libs/jsonschema/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@

v, err = fromString("1.1", NumberType)
assert.NoError(t, err)
// Floating point conversions are not perfect
assert.Less(t, (v.(float64) - 1.1), 0.000001)
assert.Equal(t, 1.1, v)

Check failure on line 98 in libs/jsonschema/utils_test.go

View workflow job for this annotation

GitHub Actions / lint

float-compare: use assert.InEpsilon (or InDelta) (testifylint)

v, err = fromString("12345", IntegerType)
assert.NoError(t, err)
assert.Equal(t, int64(12345), v)

v, err = fromString("123", NumberType)
assert.NoError(t, err)
assert.InDelta(t, float64(123), v.(float64), 0.0001)
assert.Equal(t, float64(123), v)

Check failure on line 106 in libs/jsonschema/utils_test.go

View workflow job for this annotation

GitHub Actions / lint

float-compare: use assert.InEpsilon (or InDelta) (testifylint)

_, err = fromString("qrt", ArrayType)
assert.EqualError(t, err, "cannot parse string as object of type array. Value of string: \"qrt\"")
Expand Down
Loading