-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Description
Due to the division in the to_id function when encoding numbers the loop continues until the results is smaller than the smallest possible float value, creating large encoded string
Ex.
irb(main):104> sqids = Sqids.new
=>
#<Sqids:0x0000ffff758d57a0
...
irb(main):105> sqids.encode([3.1])
=> "EBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBf"
irb(main):106>
def to_id(num, alphabet)
...
result = num
loop do
id.unshift(chars[result % chars.length])
result /= chars.length # <- here results never reaches 0 if its a float
break unless result.positive?
end
...
end
I have a PR for mapping all the values passed into encode from floats to integers which is what was done in the original HashIds gem
#8
Metadata
Metadata
Assignees
Labels
No labels