Skip to content

Commit

Permalink
Merge pull request #114 from iainbeeston/nonlatin_uris
Browse files Browse the repository at this point in the history
Handle non-latin uris
  • Loading branch information
hoxworth committed Sep 5, 2014
2 parents 23174fe + 63926b2 commit 3d76a38
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/json-schema/attributes/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def self.validate(current_schema, data, fragments, processor, validator, options
if data.is_a?(String)
error_message = "The property '#{build_fragment(fragments)}' must be a valid URI"
begin
URI.parse(data)
URI.parse(URI.escape(data))
rescue URI::InvalidURIError
validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors])
end
Expand Down
3 changes: 3 additions & 0 deletions test/test_jsonschema_draft3.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/json-schema'

Expand Down Expand Up @@ -1092,6 +1093,7 @@ def test_format_union
def test_format_uri
data1 = {"a" => "http://gitbuh.com"}
data2 = {"a" => "::boo"}
data3 = {"a" => "http://ja.wikipedia.org/wiki/メインページ"}

schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
Expand All @@ -1101,6 +1103,7 @@ def test_format_uri

assert(JSON::Validator.validate(schema,data1))
assert(!JSON::Validator.validate(schema,data2))
assert(JSON::Validator.validate(schema,data3))
end


Expand Down
3 changes: 3 additions & 0 deletions test/test_jsonschema_draft4.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/json-schema'

Expand Down Expand Up @@ -1011,6 +1012,7 @@ def test_format_datetime
def test_format_uri
data1 = {"a" => "http://gitbuh.com"}
data2 = {"a" => "::boo"}
data3 = {"a" => "http://ja.wikipedia.org/wiki/メインページ"}

schema = {
"$schema" => "http://json-schema.org/draft-04/schema#",
Expand All @@ -1020,6 +1022,7 @@ def test_format_uri

assert(JSON::Validator.validate(schema,data1))
assert(!JSON::Validator.validate(schema,data2))
assert(JSON::Validator.validate(schema,data3))
end


Expand Down

0 comments on commit 3d76a38

Please sign in to comment.