Skip to content

Commit

Permalink
Fix URI fragment decoding in instance get()
Browse files Browse the repository at this point in the history
  • Loading branch information
hudlow authored and jdesrosiers committed Mar 11, 2024
1 parent 94dfd39 commit fbf67a2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
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

0 comments on commit fbf67a2

Please sign in to comment.