Skip to content

Commit

Permalink
Ensure normalized_uri is used for ref URIs too
Browse files Browse the repository at this point in the history
  • Loading branch information
RST-J committed Nov 27, 2014
1 parent 6f1147d commit 3fac158
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/json-schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def absolutize_ref_uri(ref, parent_schema_uri)

uri = parent_schema_uri.clone
uri.fragment = ''
uri.join(ref_uri.path)
normalized_uri(uri.join(ref_uri.path))
end

# Build all schemas with IDs, mapping out the namespace
Expand Down Expand Up @@ -582,6 +582,7 @@ def normalized_uri(data)
uri = Addressable::URI.parse(data)
# Check for absolute path
if uri.relative?
data = data.to_s
data = "#{Dir.pwd}/#{data}" if data[0,1] != '/'
uri = Addressable::URI.convert_path(data)
end
Expand Down
12 changes: 9 additions & 3 deletions test/schemas/ref john with spaces schema.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{ "$schema" : "http://json-schema.org/draft-04/schema#"
, "type" : "string"
, "pattern" : "john"
{
"$schema" : "http://json-schema.org/draft-04/schema#",
"type" : "object",
"properties": {
"first": {
"type": "string",
"enum": ["john"]
}
}
}
6 changes: 3 additions & 3 deletions test/test_uri_related.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_schema_ref_with_empty_fragment
}
}
}
data = { "names" => ['john'] }
data = { "first" => "john" }
assert_valid schema, data
end

Expand All @@ -47,13 +47,13 @@ def test_schema_ref_from_file_with_spaces
"type"=> "array",
"items"=> {
"anyOf"=> [
{ "$ref" => "test/schemas/ref john with spaces schema.json" },
{ "$ref" => "test/schemas/ref john with spaces schema.json" }
]
}
}
}
}
data = { "names" => ['john'] }
data = { "first" => "john" }
assert_valid schema, data
end
end

0 comments on commit 3fac158

Please sign in to comment.