lib/json-schema/validator.rb in json-schema-0.1.11 vs lib/json-schema/validator.rb in json-schema-0.1.12
- old
+ new
@@ -457,11 +457,13 @@
temp_uri = URI.parse(current_schema.schema['$ref'])
if temp_uri.relative?
temp_uri = current_schema.uri.clone
# Check for absolute path
path = current_schema.schema['$ref'].split("#")[0]
- if path[0,1] == "/"
+ if path.nil? || path == ''
+ temp_uri.path = current_schema.uri.path
+ elsif path[0,1] == "/"
temp_uri.path = Pathname.new(path).cleanpath.to_s
else
temp_uri.path = (Pathname.new(current_schema.uri.path).parent + path).cleanpath.to_s
end
temp_uri.fragment = current_schema.schema['$ref'].split("#")[1]
@@ -507,12 +509,19 @@
def load_ref_schema(parent_schema,ref)
uri = URI.parse(ref)
if uri.relative?
uri = parent_schema.uri.clone
+
# Check for absolute path
path = ref.split("#")[0]
- if path[0,1] == '/'
+
+ # This is a self reference and thus the schema does not need to be re-loaded
+ if path.nil? || path == ''
+ return
+ end
+
+ if path && path[0,1] == '/'
uri.path = Pathname.new(path).cleanpath.to_s
else
uri.path = (Pathname.new(parent_schema.uri.path).parent + path).cleanpath.to_s
end
uri.fragment = nil
\ No newline at end of file