lib/hexapdf/dictionary.rb in hexapdf-0.14.0 vs lib/hexapdf/dictionary.rb in hexapdf-0.14.1

- old
+ new

@@ -153,10 +153,13 @@ # # * Automatically wraps hash values in specific subclasses of this class if field information is # available (see ::define_field). # # * Returns the default value if one is specified and no value is available. + # + # Note: This method may throw a "can't add a new key into hash during iteration" error in + # certain cases because it potentially modifies the underlying hash! def [](name) field = self.class.field(name) data = if key?(name) value[name] elsif field&.default? @@ -253,11 +256,11 @@ end end # Iterates over all currently set fields and those that are required. def each_set_key_or_required_field #:yields: name, field - value.each_key {|name| yield(name, self.class.field(name)) } + value.keys.each {|name| yield(name, self.class.field(name)) } self.class.each_field do |name, field| yield(name, field) if field.required? && !value.key?(name) end end @@ -299,10 +302,10 @@ end end # Check the value of the field against the allowed values. if field.allowed_values && !field.allowed_values.include?(obj) - yield("Field #{name} does not contain an allowed value") + yield("Field #{name} does not contain an allowed value: #{obj.inspect}") end # Check if field value needs to be (in)direct unless field.indirect.nil? obj = value[name] # we need the unwrapped object!