Skip to content

Commit b9ebce0

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 3c50306 commit b9ebce0

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77

88
### Fixed
99
- Corrected the draft6 schema id to `http://json-schema.org/draft/schema#`
10-
- Rescue URI error when initializing a data string that contains a colon
10+
- Rescue URI error when initializing a data string that contains a colon
11+
- Data that looks like a URI but is invalid is now treated as a string
1112

1213
## [2.8.0] - 2017-02-07
1314

lib/json-schema/validator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ def custom_open(uri)
592592
if uri.absolute? && Util::URI::SUPPORTED_PROTOCOLS.include?(uri.scheme)
593593
begin
594594
open(uri.to_s).read
595+
rescue URI::InvalidURIError => e
596+
raise JSON::Schema::UriError, e.message
595597
rescue OpenURI::HTTPError, Timeout::Error => e
596598
raise JSON::Schema::JsonLoadError, e.message
597599
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)