Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not compact before checking minItems #140

Merged
merged 1 commit into from Oct 26, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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