Skip to content

Commit

Permalink
Fix handling of weird numbers in INI files
Browse files Browse the repository at this point in the history
  • Loading branch information
farski committed Sep 20, 2023
1 parent 9e8a9bb commit ab07388
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/prx-ruby-aws-creds/lib/prx-ruby-aws-creds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@
CACHE_DIRECTORY = "#{Dir.home}/.aws/ruby/cache"
AWS_CONFIG_FILE = ENV["AWS_CONFIG_FILE"] || "#{Dir.home}/.aws/config"

# Normally IniFile tries to be clever about detecting number values in the file
# and casting them to Integers and Floats. This breaks on a value like
# 048723829744, becuase Integer() tries to treat that as an octal, but fails
# since it includes 8s and 9s, but Float(048723829744) treats it like a decimal
# and returns 48723829744.0. Even if Integer() didn't fail it would drop the
# leading zero. We need to just treat these values as strings, so this gets
# rid of the fancy typecasting.
class IniFile
class Parser
def typecast( value )
case value
when %r/\Atrue\z/i; true
when %r/\Afalse\z/i; false
when %r/\A\s*\z/i; nil
else
unescape_value(value)
end
end
end
end

class PrxRubyAwsCreds
class << self
# The cache key is based on the parameters used to request temporary
Expand Down

0 comments on commit ab07388

Please sign in to comment.