Skip to content

Commit d5a4ebd

Browse files
committed
Data that looks like a URI but is invalid should be treated as a
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.
1 parent 2f95d53 commit d5a4ebd

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1414
- Rescue URI error when initializing a data string that contains a colon
1515
- Fragments with an odd number of components no longer raise an `undefined method `validate'`
1616
error
17+
- Data that looks like a URI but is invalid is now treated as a string
1718

1819
## [2.8.0] - 2017-02-07
1920

lib/json-schema/validator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ def custom_open(uri)
594594
if uri.absolute? && Util::URI::SUPPORTED_PROTOCOLS.include?(uri.scheme)
595595
begin
596596
open(uri.to_s).read
597+
rescue URI::InvalidURIError => e
598+
raise JSON::Schema::UriError, e.message
597599
rescue OpenURI::HTTPError, Timeout::Error => e
598600
raise JSON::Schema::JsonLoadError, e.message
599601
end

test/initialize_data_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def test_parse_invalid_uri_string
109109
end
110110

111111
assert_raises(JSON::Schema::JsonLoadError) { JSON::Validator.validate(schema, data, :uri => true) }
112+
113+
assert(JSON::Validator.validate(schema, "http://a/%%30%30"))
112114
end
113115

114116
def test_parse_invalid_scheme_string

0 commit comments

Comments
 (0)