Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow resolution of fragments with escaped parts #463

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/json-schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def initialize(schema_data, data, opts={})

def schema_from_fragment(base_schema, fragment)
schema_uri = base_schema.uri
fragments = fragment.split("/")
fragments = fragment.split("/").map { |f| f.gsub('~0', '~').gsub('~1', '/') }

# ensure the first element was a hash, per the fragment spec
if fragments.shift != "#"
Expand Down
17 changes: 17 additions & 0 deletions test/fragment_resolution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,21 @@ def test_array_fragment_resolution
assert_valid schema, 5, :fragment => "#/properties/a/anyOf/0"
refute_valid schema, 5, :fragment => "#/properties/a/anyOf/1"
end

def test_fragment_with_escape_sequences_resolution
schema = {
"content" => {
"application/json" => {
"type" => "object",
"required" => ["a"],
"properties" => {
"a" => {"type" => "integer"}
}
}
}
}

assert_valid schema, {"a" => 1}, :fragment => "#/content/application~1json"
refute_valid schema, {}, :fragment => "#/content/application~1json"
end
end