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

Fix URI fragment decoding in instance get() #55

Merged
merged 2 commits into from
Mar 11, 2024
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
53 changes: 53 additions & 0 deletions annotations/tests/pointer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[
{
"title": "annotation pointers are properly decoded",
"schema": {
"properties": {
"paths": {
"properties": {
"/pets/{id}": {
"title": "path",
"properties": {
"get": {
"title": "method"
}
}
}
}
}
}
},
"subjects": [
{
"instance": { "paths": { "/pets/{id}": {} } },
"assertions": [
{
"location": "#/paths/~1pets~1{id}",
"keyword": "title",
"expected": ["path"]
}
]
},
{
"instance": { "paths": { "/pets/{id}": {} } },
"assertions": [
{
"location": "#/paths/~1pets~1%7Bid%7D",
"keyword": "title",
"expected": ["path"]
}
]
},
{
"instance": { "paths": { "/pets/{id}": { "get": {} } } },
"assertions": [
{
"location": "#/paths/~1pets~1%7Bid%7D/get",
"keyword": "title",
"expected": ["method"]
}
]
}
]
}
]
4 changes: 2 additions & 2 deletions lib/instance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { append as pointerAppend, get as pointerGet } from "@hyperjump/json-pointer";
import { toAbsoluteIri } from "@hyperjump/uri";
import { jsonTypeOf } from "./common.js";
import { jsonTypeOf, uriFragment } from "./common.js";
import { Reference } from "@hyperjump/browser/jref";


Expand All @@ -17,7 +17,7 @@ export const get = (url, instance = nil) => {
throw Error(`No JSON document found at '${url.split("#")[0]}'`);
}

const pointer = url.substr(1);
const pointer = uriFragment(url);
return {
...instance,
pointer: pointer,
Expand Down