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 Jun 30, 2017
1 parent 3ec4d62 commit 80f4740
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed
- Corrected the draft6 schema id to `http://json-schema.org/draft/schema#`
- Rescue URI error when initializing a data string that contains a colon
- Rescue URI error when initializing a data string that contains a colon
- 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 @@ -592,6 +592,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 80f4740

Please sign in to comment.