Skip to content

Commit

Permalink
Do not compact before checking minItems
Browse files Browse the repository at this point in the history
  • Loading branch information
pd committed Oct 25, 2014
1 parent 909eeff commit b363c64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/json-schema/attributes/minitems.rb
Expand Up @@ -4,7 +4,7 @@ module JSON
class Schema
class MinItemsAttribute < Attribute
def self.validate(current_schema, data, fragments, processor, validator, options = {})
if data.is_a?(Array) && (data.compact.size < current_schema.schema['minItems'])
if data.is_a?(Array) && (data.size < current_schema.schema['minItems'])
message = "The property '#{build_fragment(fragments)}' did not contain a minimum number of items #{current_schema.schema['minItems']}"
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
end
Expand Down
18 changes: 18 additions & 0 deletions test/test_minitems.rb
@@ -0,0 +1,18 @@
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/json-schema'

class MinItemsTest < Test::Unit::TestCase
def test_minitems_nils
schema = {
"type" => "array",
"minItems" => 1,
"items" => { "type" => "object" }
}
data = [nil]

errors = JSON::Validator.fully_validate(schema, [nil])
assert_equal(errors.length, 1)
assert(errors[0] !~ /minimum/)
assert(errors[0] =~ /NilClass/)
end
end

0 comments on commit b363c64

Please sign in to comment.