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

Integer as string should be defined as string #497

Merged
merged 6 commits into from
Jul 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update validator.rb
  • Loading branch information
mohanapriya2308 authored Jul 21, 2023
commit ec9396b7121e5e96614306e8a82995127d32e6e3
4 changes: 3 additions & 1 deletion lib/json-schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def initialize(schema_data, opts = {})

configured_validator = self.class.validator_for_name(@options[:version])
@options[:schema_reader] ||= self.class.schema_reader
@options[:parse_integer] = true if @options[:parse_integer].nil?

@validation_options = @options[:record_errors] ? { record_errors: true } : {}
@validation_options[:insert_defaults] = true if @options[:insert_defaults]
Expand Down Expand Up @@ -578,7 +579,8 @@ def initialize_data(data)
elsif data.is_a?(String)
begin
# Check if the string is valid integer
data = data.match?(/\A[+-]?\d+\z/) ? data : self.class.parse(data)
strict_convert = data.match?(/\A[+-]?\d+\z/) && !@options[:parse_integer]
data = strict_convert ? data : self.class.parse(data)
rescue JSON::Schema::JsonParseError
begin
json_uri = Util::URI.normalized_uri(data)
Expand Down