Skip to content
Merged
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 avro_schema/frontend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,10 @@ copy_data = function(stack, schema, data, visited)
stack.remove_last()
return data
elseif schematype == 'long' then
local n = tonumber(data)
local n
if type(data) == 'number' or type(data) == 'cdata' then
n = tonumber(data)
end
Comment on lines +772 to +775
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative way that also could be used.
Do something like

local _
_ = data > 0 -- it throws for non-numeric types (e.g. for strings)

if not n then
stack.push(schema, data)
error()
Expand Down
6 changes: 6 additions & 0 deletions test/ddt_suite/validate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ t {
validate_error = 'Not a long: 9223372036854775808ULL'
}

t {
schema = '"long"',
validate = '"42"',
validate_error = 'Not a long: 42'
}

-- note: IEEE 754 double precision floating-point numbers encode
-- fraction with 52 bits, hence when the value is 2^63,
-- the delta must be at least 2^11 (2048) to make a difference.
Expand Down