Skip to content

Commit

Permalink
Data that looks like a URI but is invalid should be treated as a
Browse files Browse the repository at this point in the history
string

There's a bug where if you pass a string as data and it looks like a
URI, we try to parse it and load the data from that location. However,
if parsing fails, we should give up trying to load remote data and
treat the data as a string instead.
  • Loading branch information
iainbeeston committed Jul 6, 2017
1 parent 2f95d53 commit d5a4ebd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Rescue URI error when initializing a data string that contains a colon
- Fragments with an odd number of components no longer raise an `undefined method `validate'`
error
- Data that looks like a URI but is invalid is now treated as a string

## [2.8.0] - 2017-02-07

Expand Down
2 changes: 2 additions & 0 deletions lib/json-schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ def custom_open(uri)
if uri.absolute? && Util::URI::SUPPORTED_PROTOCOLS.include?(uri.scheme)
begin
open(uri.to_s).read
rescue URI::InvalidURIError => e
raise JSON::Schema::UriError, e.message
rescue OpenURI::HTTPError, Timeout::Error => e
raise JSON::Schema::JsonLoadError, e.message
end
Expand Down
2 changes: 2 additions & 0 deletions test/initialize_data_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def test_parse_invalid_uri_string
end

assert_raises(JSON::Schema::JsonLoadError) { JSON::Validator.validate(schema, data, :uri => true) }

assert(JSON::Validator.validate(schema, "http://a/%%30%30"))
end

def test_parse_invalid_scheme_string
Expand Down

0 comments on commit d5a4ebd

Please sign in to comment.