From 37a5f376d02ecaa5650953fb22e2a62952284ffe Mon Sep 17 00:00:00 2001 From: Jason Desrosiers Date: Wed, 4 Nov 2026 23:13:45 -0800 Subject: [PATCH 1/2] Use WHATWG URLs instead of @hyperjump/uri Browser is a WHATWG client, so references are resolved with `new URL` and node locations are encoded with the URL fragment percent-encode set. Retrieval already used URLs, so this removes a second idea of what an identifier is, and the @hyperjump/uri dependency. Co-Authored-By: Claude Opus 5.5 --- design/components/json-ast.md | 14 ++++-- design/principles/README.md | 2 +- design/principles/retrieval-uses-urls.md | 6 --- design/principles/urls-not-uris.md | 30 ++++++++++++ package-lock.json | 11 ----- package.json | 1 - src/hyperjump/browsing.js | 4 +- src/hyperjump/file-uris.js | 20 +++++--- src/hyperjump/get.test.js | 2 +- src/hyperjump/hyperjump.js | 28 +++++------ .../uri-schemes/file-scheme-plugin.js | 8 ++-- .../uri-schemes/http-scheme-plugin.js | 6 +-- src/hyperjump/urls.js | 18 +++++++ src/jref/jref-util.js | 3 +- src/jref/jref-util.test.js | 19 ++++---- src/json/location.d.ts | 6 +-- src/json/location.js | 11 ++++- src/json/location.test.js | 47 +++++++++---------- 18 files changed, 140 insertions(+), 96 deletions(-) delete mode 100644 design/principles/retrieval-uses-urls.md create mode 100644 design/principles/urls-not-uris.md create mode 100644 src/hyperjump/urls.js diff --git a/design/components/json-ast.md b/design/components/json-ast.md index 9aa9130..c5b86c9 100644 --- a/design/components/json-ast.md +++ b/design/components/json-ast.md @@ -92,11 +92,15 @@ status with it: ## Locations -- A node's location is a URI whose fragment is a JSON Pointer. Pointer - segments are percent-encoded where a fragment requires it - (`appendToLocation`, `@hyperjump/uri`'s `encodeIriFragment`), so - locations are valid, normalized IRIs. `get` decodes a fragment before - following it as a JSON Pointer. +- A node's location is a URL whose fragment is a JSON Pointer. Pointer + segments are percent-encoded with the URL fragment percent-encode set + (`appendToLocation`), so a location is what a URL parser makes of it and + can be compared to a resolved reference. `%` is encoded too, because + `get` decodes a fragment before following it as a JSON Pointer. +- The set is encoded directly instead of by a URL parser, because a parser + removes tabs and newlines. +- A lone surrogate in a property name is encoded as U+FFFD, as a URL + encodes it, so two property names can have the same location. - `appendToLocation` caches the encoded form of each segment, because encoding was most of the time `fromJs` took (see [Node locations](../benchmarks/node-locations.md)). diff --git a/design/principles/README.md b/design/principles/README.md index 4dcc75b..b88d4ba 100644 --- a/design/principles/README.md +++ b/design/principles/README.md @@ -4,6 +4,6 @@ The rules decisions are made by. - [A generic client](generic-client.md) - [`retrieve` is only for retrieving](retrieve-is-for-retrieving.md) -- [Retrieval uses URLs](retrieval-uses-urls.md) +- [URLs, not URIs](urls-not-uris.md) - [Documents aren't trusted](documents-arent-trusted.md) - [Parsing never fails](parsing-never-fails.md) diff --git a/design/principles/retrieval-uses-urls.md b/design/principles/retrieval-uses-urls.md deleted file mode 100644 index d9873ca..0000000 --- a/design/principles/retrieval-uses-urls.md +++ /dev/null @@ -1,6 +0,0 @@ -# Retrieval uses URLs - -What's retrieved is a URL, so retrieval uses WHATWG URLs (`new URL`, -`pathToFileURL`). `@hyperjump/uri` is for what URLs don't do, like -resolving IRIs and encoding locations. Applications that identify -documents by URIs that aren't URLs handle that themselves. diff --git a/design/principles/urls-not-uris.md b/design/principles/urls-not-uris.md new file mode 100644 index 0000000..c3cad73 --- /dev/null +++ b/design/principles/urls-not-uris.md @@ -0,0 +1,30 @@ +# URLs, not URIs + +Browser is a WHATWG client, so what it identifies is a WHATWG URL. A +reference's `$ref` is resolved with `new URL`, what's retrieved is a URL +without its fragment, and a node's location is a URL that a URL parser +leaves as it is. `fetch`, browsers, and Node.js already agree on what a URL +is, so Browser doesn't need a URI library or rules of its own. + +- A reference is resolved the way a browser resolves a link. It's + percent-encoded where a URL requires it, so a `$ref` with non-ASCII + characters resolves to its encoded form. A host is lowercased, and a + special scheme's host is converted to ASCII. +- Applications that identify documents by URIs that aren't URLs handle + that themselves. + +Rejected: + +- Resolving references by RFC 3986 with `@hyperjump/uri`. It resolves a + relative reference against any scheme and keeps IRIs as they are. But + retrieval uses URLs, so a session would have two ideas of what an + identifier is. A reference resolved by one and retrieved by the other + can be a different resource, as with a `%2e%2e` segment, which a URL + treats as `..` and RFC 3986 doesn't. It's also a dependency for what the + platform already does. + +Known limitations: + +- A relative reference can't be resolved against a URL with an opaque path, + like `urn:example:a`. Only a fragment can. Parsing a document with one + throws. diff --git a/package-lock.json b/package-lock.json index 0592005..84afcda 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "license": "MIT", "dependencies": { "@hyperjump/json-pointer": "^2.0.0", - "@hyperjump/uri": "^1.4.0", "@types/unist": "^3.0.3", "content-type": "^3.1.1", "http-cache-semantics": "^4.3.0", @@ -252,16 +251,6 @@ "url": "https://github.com/sponsors/hyperjump-io" } }, - "node_modules/@hyperjump/uri": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@hyperjump/uri/-/uri-1.4.0.tgz", - "integrity": "sha512-A6eBnSLNb6GdJHnYnA0sDutV950mWNmmlWgASwIoZvXqtXcYKBeEhbGrXpHeyHHInC/LHVt8zNanILp2S2oRXg==", - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/jdesrosiers" - } - }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", diff --git a/package.json b/package.json index 55611a3..8f445aa 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,6 @@ }, "dependencies": { "@hyperjump/json-pointer": "^2.0.0", - "@hyperjump/uri": "^1.4.0", "@types/unist": "^3.0.3", "content-type": "^3.1.1", "http-cache-semantics": "^4.3.0", diff --git a/src/hyperjump/browsing.js b/src/hyperjump/browsing.js index 5ecd28e..29a15b6 100644 --- a/src/hyperjump/browsing.js +++ b/src/hyperjump/browsing.js @@ -1,5 +1,5 @@ -import { toAbsoluteIri } from "@hyperjump/uri"; import { jsonArrayIter, jsonObjectEntries, jsonObjectHas, jsonObjectKeys, jsonObjectValues, jsonStep, jsonValue } from "../json/jsonast-util.js"; +import { withoutFragment } from "./urls.js"; /** * @import { JrefNode } from "../jref/jref-ast.d.ts" @@ -57,7 +57,7 @@ export const jrefValue = /** @type API.jrefValue */ ((/** @type JrefNode */ node */ const follow = async (session, node) => { if (node.type === "reference") { - return session.get(node.href, { referencedFrom: toAbsoluteIri(node.location) }); + return session.get(node.href, { referencedFrom: withoutFragment(node.location) }); } else { return node; } diff --git a/src/hyperjump/file-uris.js b/src/hyperjump/file-uris.js index 7fd2368..2ba08c6 100644 --- a/src/hyperjump/file-uris.js +++ b/src/hyperjump/file-uris.js @@ -1,4 +1,3 @@ -import { parseIri, resolveIri, toRelativeIri } from "@hyperjump/uri"; import { contextUri } from "#context-uri"; /** @@ -12,15 +11,24 @@ export const relativeFileUri = (uri) => { return uri; } + // Parsing it normalizes it, so a scheme written as 'FILE:' is relative too + const url = new URL(uri); + const suffix = url.search + url.hash; + // There are no files to be relative to where the working directory isn't // a folder, like in a browser const base = contextUri(); if (!/^file:/i.test(base)) { - const { path, fragment } = parseIri(uri); - const name = path.slice(path.lastIndexOf("/") + 1); - return fragment === undefined ? name : `${name}#${fragment}`; + return url.pathname.slice(url.pathname.lastIndexOf("/") + 1) + suffix; + } + + // The working directory's URL ends with a `/`, so its last segment is empty + const directories = new URL(base).pathname.split("/").slice(0, -1); + const segments = url.pathname.split("/"); + let common = 0; + while (common < directories.length && common < segments.length - 1 && directories[common] === segments[common]) { + common++; } - // Resolving it normalizes it, so a scheme written as 'FILE:' is relative too - return toRelativeIri(base, resolveIri(uri, base)); + return "../".repeat(directories.length - common) + segments.slice(common).join("/") + suffix; }; diff --git a/src/hyperjump/get.test.js b/src/hyperjump/get.test.js index 586ce6e..8f5bb2c 100644 --- a/src/hyperjump/get.test.js +++ b/src/hyperjump/get.test.js @@ -195,7 +195,7 @@ describe("JSON Browser", () => { const subject = await session.get(`${testDomain}/foo#/a%5Eb/c%20d`); expect(toJson(subject)).to.equal(`42`); - expect(subject.location).to.equal(`${testDomain}/foo#/a%5Eb/c%20d`); + expect(subject.location).to.equal(`${testDomain}/foo#/a^b/c%20d`); }); test("an unnecessarily encoded fragment finds the same node", async () => { diff --git a/src/hyperjump/hyperjump.js b/src/hyperjump/hyperjump.js index c506c6b..1dfb158 100644 --- a/src/hyperjump/hyperjump.js +++ b/src/hyperjump/hyperjump.js @@ -1,4 +1,3 @@ -import { parseIri, resolveIri, toAbsoluteIri } from "@hyperjump/uri"; import { contextUri } from "#context-uri"; import { defaultUriSchemePlugins } from "#default-uri-scheme-plugins"; import { JsonMediaTypePlugin } from "./media-types/json-media-type-plugin.js"; @@ -7,6 +6,7 @@ import { jsonPointerGet } from "../json/jsonast-util.js"; import { acceptHeader, fragmentPointer, mediaTypeByExtension, mediaTypePluginFor } from "./media-type-plugins.js"; import { AllowedUrls, configSource, resolveAllowRetrieval, sessionSource } from "./allowed-urls.js"; import { relativeFileUri } from "./file-uris.js"; +import { resolveUrl, withoutFragment } from "./urls.js"; /** * @import { JrefNode } from "../jref/jref-ast.d.ts" @@ -189,20 +189,20 @@ export class Session { * @returns {Promise} */ async #get(uri, options, referenceChain) { - uri = resolveIri(uri, this.#contextUri); + uri = resolveUrl(uri, this.#contextUri); if (referenceChain.includes(uri)) { throw new ReferenceCycleError([...referenceChain, uri]); } referenceChain = [...referenceChain, uri]; - const { fragment } = parseIri(uri); + const { hash } = new URL(uri); // Subclasses can override getDocument, so every lookup goes through it const document = await this.getDocument(uri, options); - const cursor = fragment === undefined ? "" : this.#hyperjump.fragmentPointer(document, fragment); + const cursor = hash === "" ? "" : this.#hyperjump.fragmentPointer(document, hash.slice(1)); const node = jsonPointerGet(cursor, document.children[0]); if (node.type === "reference") { - return this.#get(node.href, { referencedFrom: toAbsoluteIri(node.location) }, referenceChain); + return this.#get(node.href, { referencedFrom: withoutFragment(node.location) }, referenceChain); } else { return node; } @@ -210,8 +210,8 @@ export class Session { /** @type API.Session["getDocument"] */ async getDocument(uri, options = {}) { - uri = resolveIri(uri, this.#contextUri); - const id = toAbsoluteIri(uri); + uri = resolveUrl(uri, this.#contextUri); + const id = withoutFragment(uri); this.#cache[id] ??= this.#retrieveDocument(uri, options).catch((/** @type unknown */ error) => { // A failure isn't cached, so it can be tried again @@ -234,12 +234,12 @@ export class Session { * @type (uri: string, options: API.GetOptions) => Promise */ async #retrieveDocument(uri, options) { - const id = toAbsoluteIri(uri); + const id = withoutFragment(uri); let response; let url = uri; for (let redirects = 0; ; redirects++) { - const hop = toAbsoluteIri(url); + const hop = withoutFragment(url); if (!await this.#allowedUrls.allows(hop)) { throw this.#notAllowedError(id, hop); } @@ -263,13 +263,13 @@ export class Session { // `retrieve` gives every response a URL. The fragment isn't part of // what's retrieved. try { - url = toAbsoluteIri(resolveIri(location, response.url)); + url = withoutFragment(new URL(location, response.url).href); } catch (error) { throw new RetrievalError(uri, { cause: error }); } } - if (response.url !== toAbsoluteIri(url) && !await this.#allowedUrls.allows(response.url)) { + if (response.url !== withoutFragment(url) && !await this.#allowedUrls.allows(response.url)) { await response.body?.cancel(); throw this.#notAllowedError(id, response.url); } @@ -280,7 +280,7 @@ export class Session { // References within the document are relative to the URI it was // retrieved from, which can differ from the requested URI (redirects, // symlinks), so it needs to be cached under both. - this.#cache[toAbsoluteIri(response.url)] ??= Promise.resolve(document); + this.#cache[withoutFragment(response.url)] ??= Promise.resolve(document); return document; } catch (error) { @@ -298,7 +298,7 @@ export class Session { * @type (uri: string, options: API.GetOptions) => Promise */ async #retrieve(uri, options) { - const { scheme } = parseIri(uri); + const scheme = new URL(uri).protocol.slice(0, -1); const plugin = this.#hyperjump.uriSchemePlugins.get(scheme); if (!plugin) { @@ -312,7 +312,7 @@ export class Session { mediaTypeByExtension: (uri) => mediaTypeByExtension(mediaTypePlugins, uri) }); if (!response.url) { - Object.defineProperty(response, "url", { value: toAbsoluteIri(uri) }); + Object.defineProperty(response, "url", { value: withoutFragment(uri) }); } return response; diff --git a/src/hyperjump/uri-schemes/file-scheme-plugin.js b/src/hyperjump/uri-schemes/file-scheme-plugin.js index acca043..4b83f6b 100644 --- a/src/hyperjump/uri-schemes/file-scheme-plugin.js +++ b/src/hyperjump/uri-schemes/file-scheme-plugin.js @@ -1,10 +1,10 @@ import { createReadStream } from "node:fs"; import { realpath } from "node:fs/promises"; import { fileURLToPath, pathToFileURL } from "node:url"; -import { parseIri, toAbsoluteIri } from "@hyperjump/uri"; import { Readable } from "node:stream"; import { FileNotFoundError } from "../hyperjump.js"; import { relativeFileUri } from "../file-uris.js"; +import { withoutFragment } from "../urls.js"; /** * @import * as API from "./file-scheme-plugin.d.ts" @@ -19,9 +19,7 @@ export class FileUriSchemePlugin { /** @type API.FileUriSchemePlugin["retrieve"] */ async retrieve(uri, options) { if (options.referencedFrom) { - const { scheme } = parseIri(options.referencedFrom); - - if (scheme !== "file") { + if (new URL(options.referencedFrom).protocol !== "file:") { throw Error(`Accessing a file (${relativeFileUri(uri)}) from a non-filesystem context (${options.referencedFrom}) is not allowed`); } } @@ -43,7 +41,7 @@ export class FileUriSchemePlugin { } throw error; } - const responseUri = realFilePath === filePath ? toAbsoluteIri(uri) : pathToFileURL(realFilePath).toString(); + const responseUri = realFilePath === filePath ? withoutFragment(uri) : pathToFileURL(realFilePath).toString(); // A file doesn't have a media type, so it's the one its extension has const headers = new Headers(); diff --git a/src/hyperjump/uri-schemes/http-scheme-plugin.js b/src/hyperjump/uri-schemes/http-scheme-plugin.js index 1807efb..ee6c889 100644 --- a/src/hyperjump/uri-schemes/http-scheme-plugin.js +++ b/src/hyperjump/uri-schemes/http-scheme-plugin.js @@ -1,7 +1,7 @@ import CachePolicy from "http-cache-semantics"; -import { toAbsoluteIri } from "@hyperjump/uri"; import { defaultHttpCache } from "#default-http-cache"; import { redirectMode } from "#redirect-mode"; +import { withoutFragment } from "../urls.js"; /** * @import { HttpCacheStore } from "./http-cache-store.d.ts" @@ -86,12 +86,12 @@ export class HttpUriSchemePlugin { const headers = new Headers(response.headers); headers.set("content-type", mediaType); const typedResponse = new Response(response.body, { status: response.status, statusText: response.statusText, headers }); - Object.defineProperty(typedResponse, "url", { value: response.url || toAbsoluteIri(uri) }); + Object.defineProperty(typedResponse, "url", { value: response.url || withoutFragment(uri) }); return typedResponse; } - const url = toAbsoluteIri(uri); + const url = withoutFragment(uri); const key = JSON.stringify([url, accept]); let pending = this.#pending.get(key); if (!pending) { diff --git a/src/hyperjump/urls.js b/src/hyperjump/urls.js new file mode 100644 index 0000000..ce975a1 --- /dev/null +++ b/src/hyperjump/urls.js @@ -0,0 +1,18 @@ +/** + * Resolve a URL against the context URI. Where there's no context URI, as + * in a browser without a document, only an absolute URL can be resolved. + * + * @type (url: string, base: string) => string + */ +export const resolveUrl = (url, base) => new URL(url, base === "" ? undefined : base).href; + +/** + * The URL of what's retrieved, which is the URL without its fragment + * + * @type (url: string) => string + */ +export const withoutFragment = (url) => { + const parsed = new URL(url); + parsed.hash = ""; + return parsed.href; +}; diff --git a/src/jref/jref-util.js b/src/jref/jref-util.js index 5ddbd8c..6169072 100644 --- a/src/jref/jref-util.js +++ b/src/jref/jref-util.js @@ -1,4 +1,3 @@ -import { resolveIri } from "@hyperjump/uri"; import { fromJson, hasStatus as jsonHasStatus } from "../json/jsonast-util.js"; /** @@ -40,7 +39,7 @@ const annotateReferences = (node, uri) => { Object.assign(node, { type: "reference", // Without a base URI, relative references can't be resolved - href: uri === undefined ? valueNode.value : resolveIri(valueNode.value, uri) + href: uri === undefined ? valueNode.value : new URL(valueNode.value, uri).href }); isReference = true; } diff --git a/src/jref/jref-util.test.js b/src/jref/jref-util.test.js index f44149f..2d4fbcd 100644 --- a/src/jref/jref-util.test.js +++ b/src/jref/jref-util.test.js @@ -1,6 +1,5 @@ import { describe, test, expect } from "vitest"; import { fromJref } from "./jref-util.js"; -import { resolveIri } from "@hyperjump/uri"; import { jsonStep, toJson } from "../json/jsonast-util.js"; /** @@ -146,7 +145,7 @@ describe("JRef", () => { } ], location: `${testContext}#`, - href: resolveIri("./foo", testContext), + href: new URL("./foo", testContext).href, position: { start: { line: 1, column: 1, offset: 0 }, end: { line: 1, column: 20, offset: 19 } @@ -239,7 +238,7 @@ describe("JRef", () => { } ], location: `${testContext}#/0`, - href: resolveIri("./foo", testContext), + href: new URL("./foo", testContext).href, position: { start: { line: 2, column: 3, offset: 4 }, end: { line: 2, column: 22, offset: 23 } @@ -369,7 +368,7 @@ describe("JRef", () => { } ], location: `${testContext}#/foo`, - href: resolveIri("./foo", testContext), + href: new URL("./foo", testContext).href, position: { start: { line: 2, column: 10, offset: 11 }, end: { line: 2, column: 29, offset: 30 } @@ -392,8 +391,8 @@ describe("JRef", () => { test("reference in the properties of a reference", () => { const subject = /** @type JrefNode */ (fromJref(`{ "$ref": "./foo", "bar": { "$ref": "./bar" } }`, testContext).node); - expect(subject).to.include({ type: "reference", href: resolveIri("./foo", testContext) }); - expect(jsonStep("bar", subject)).to.include({ type: "reference", href: resolveIri("./bar", testContext) }); + expect(subject).to.include({ type: "reference", href: new URL("./foo", testContext).href }); + expect(jsonStep("bar", subject)).to.include({ type: "reference", href: new URL("./bar", testContext).href }); }); test("$ref that isn't a string", () => { @@ -465,7 +464,7 @@ describe("JRef", () => { } ], location: "#", - href: resolveIri("./foo", testContext) + href: new URL("./foo", testContext).href }; const subject = toJson(node); expect(subject).to.equal(`{"$ref":"./foo"}`); @@ -544,7 +543,7 @@ describe("JRef", () => { } ], location: "#/1", - href: resolveIri("./foo", testContext) + href: new URL("./foo", testContext).href }, { type: "json", @@ -654,7 +653,7 @@ describe("JRef", () => { } ], location: "#/bar", - href: resolveIri("./foo", testContext) + href: new URL("./foo", testContext).href } ] } @@ -718,7 +717,7 @@ describe("JRef", () => { ] } ], - href: resolveIri("./foo", testContext), + href: new URL("./foo", testContext).href, location: "#/bar" } ] diff --git a/src/json/location.d.ts b/src/json/location.d.ts index 2655519..71bed8f 100644 --- a/src/json/location.d.ts +++ b/src/json/location.d.ts @@ -1,8 +1,8 @@ /** * Add a property name or array index to the location of a node, like - * `JsonPointer.append` does for a JSON Pointer. A location is a URI whose + * `JsonPointer.append` does for a JSON Pointer. A location is a URL whose * fragment is a JSON Pointer, so the segment is percent-encoded for use in a - * fragment. The result is a normalized IRI, so it can be compared to a - * normalized reference to the same node. + * fragment. The result is what a URL parser makes of it, so it can be + * compared to a resolved reference to the same node. */ export const appendToLocation: (segment: string, location: string) => string; diff --git a/src/json/location.js b/src/json/location.js index 897dd3c..c1971a3 100644 --- a/src/json/location.js +++ b/src/json/location.js @@ -1,5 +1,4 @@ import { pointerAppend } from "@hyperjump/json-pointer"; -import { encodeIriFragment } from "@hyperjump/uri"; /** * @import * as API from "./location.d.ts" @@ -14,11 +13,19 @@ const encodedSegments = new Map(); const maxCachedSegments = 10_000; const maxCachedSegmentLength = 100; +// The URL fragment percent-encode set, and `%`, because a fragment is decoded +// before it's followed as a JSON Pointer. A URL parser removes tabs and +// newlines, so it can't encode a segment that has them. +const fragmentEncoded = /[\0-\x20"<>`%\x7F-\u{10FFFF}]/gu; + +/** @type (fragment: string) => string */ +const encodeFragment = (fragment) => fragment.toWellFormed().replace(fragmentEncoded, encodeURIComponent); + /** @type API.appendToLocation */ export const appendToLocation = (segment, location) => { let encoded = encodedSegments.get(segment); if (encoded === undefined) { - encoded = encodeIriFragment(pointerAppend(segment, "")); + encoded = encodeFragment(pointerAppend(segment, "")); if (segment.length <= maxCachedSegmentLength) { if (encodedSegments.size >= maxCachedSegments) { encodedSegments.clear(); diff --git a/src/json/location.test.js b/src/json/location.test.js index 822c61a..96fef2d 100644 --- a/src/json/location.test.js +++ b/src/json/location.test.js @@ -1,5 +1,4 @@ import { describe, test, expect } from "vitest"; -import { normalizeIri } from "@hyperjump/uri"; import { fromJs, fromJson } from "./jsonast-util.js"; import { appendToLocation } from "./location.js"; @@ -10,56 +9,56 @@ import { appendToLocation } from "./location.js"; describe("node locations", () => { /** @type [string, string][] */ const segments = [ - ["foo", "https://example.com#/foo"], - ["$defs", "https://example.com#/$defs"], - ["rosé", "https://example.com#/rosé"], - ["a/b~c", "https://example.com#/a~1b~0c"], - ["^v", "https://example.com#/%5Ev"], - ["foo\tbar", "https://example.com#/foo%09bar"], - ["a#b", "https://example.com#/a%23b"], - ["100%", "https://example.com#/100%25"] + ["foo", "https://example.com/#/foo"], + ["$defs", "https://example.com/#/$defs"], + ["rosé", "https://example.com/#/ros%C3%A9"], + ["a/b~c", "https://example.com/#/a~1b~0c"], + ["^v", "https://example.com/#/^v"], + ["foo\tbar", "https://example.com/#/foo%09bar"], + ["a#b", "https://example.com/#/a#b"], + ["100%", "https://example.com/#/100%25"] ]; for (const [segment, expected] of segments) { test(`appendToLocation('${segment}')`, () => { - const location = appendToLocation(segment, "https://example.com#"); + const location = appendToLocation(segment, "https://example.com/#"); expect(location).to.equal(expected); - expect(normalizeIri(location)).to.equal(location); + expect(new URL(location).href).to.equal(location); }); } test("a segment encoded before is appended to the location it's given", () => { - expect(appendToLocation("a^b", "https://example.com#")).to.equal("https://example.com#/a%5Eb"); - expect(appendToLocation("a^b", "https://example.com#/c")).to.equal("https://example.com#/c/a%5Eb"); + expect(appendToLocation("a b", "https://example.com/#")).to.equal("https://example.com/#/a%20b"); + expect(appendToLocation("a b", "https://example.com/#/c")).to.equal("https://example.com/#/c/a%20b"); }); test("a long segment is encoded every time", () => { - const segment = "^".repeat(200); - const expected = `#/${"%5E".repeat(200)}`; + const segment = " ".repeat(200); + const expected = `#/${"%20".repeat(200)}`; expect(appendToLocation(segment, "#")).to.equal(expected); expect(appendToLocation(segment, "#")).to.equal(expected); }); test("segments are still encoded after more than the cache holds", () => { for (let index = 0; index < 20_000; index++) { - expect(appendToLocation(`^${index}`, "#")).to.equal(`#/%5E${index}`); + expect(appendToLocation(` ${index}`, "#")).to.equal(`#/%20${index}`); } - expect(appendToLocation("^0", "#")).to.equal("#/%5E0"); + expect(appendToLocation(" 0", "#")).to.equal("#/%200"); }); test("the parser encodes locations", () => { - const root = /** @type any */ (fromJson(`{ "a^b": [1], "c d": 2 }`, "https://example.com").node); + const root = /** @type any */ (fromJson(`{ "a b": [1], "c d": 2 }`, "https://example.com/").node); - expect(root.children[0].children[1].location).to.equal("https://example.com#/a%5Eb"); - expect(root.children[0].children[1].children[0].location).to.equal("https://example.com#/a%5Eb/0"); - expect(root.children[1].children[1].location).to.equal("https://example.com#/c%20d"); + expect(root.children[0].children[1].location).to.equal("https://example.com/#/a%20b"); + expect(root.children[0].children[1].children[0].location).to.equal("https://example.com/#/a%20b/0"); + expect(root.children[1].children[1].location).to.equal("https://example.com/#/c%20d"); }); test("fromJs encodes locations", () => { - const root = /** @type JsonNode & { jsonType: "object" } */ (fromJs({ "a^b": [1] })); + const root = /** @type JsonNode & { jsonType: "object" } */ (fromJs({ "a b": [1] })); const value = /** @type JsonNode & { jsonType: "array" } */ (root.children[0].children[1]); - expect(value.location).to.equal("#/a%5Eb"); - expect(value.children[0].location).to.equal("#/a%5Eb/0"); + expect(value.location).to.equal("#/a%20b"); + expect(value.children[0].location).to.equal("#/a%20b/0"); }); }); From 49da0d5421c955e2096f011aca724af71e8cf20f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 07:18:42 +0000 Subject: [PATCH 2/2] Bump undici from 8.12.2 to 8.12.3 Bumps [undici](https://github.com/nodejs/undici) from 8.12.2 to 8.12.3. - [Release notes](https://github.com/nodejs/undici/releases) - [Commits](https://github.com/nodejs/undici/compare/v8.12.2...v8.12.3) --- updated-dependencies: - dependency-name: undici dependency-version: 8.12.3 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 84afcda..b63822e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2606,9 +2606,9 @@ } }, "node_modules/undici": { - "version": "8.12.2", - "resolved": "https://registry.npmjs.org/undici/-/undici-8.12.2.tgz", - "integrity": "sha512-XtuDWVdqTLr3NAxm2ly9/hU6kUsJOgGh1RASzMBbsw6aWCOaQzHdW+QQDfdERjfJ2V5vL5pRPa4RetO9UfivDg==", + "version": "8.12.3", + "resolved": "https://registry.npmjs.org/undici/-/undici-8.12.3.tgz", + "integrity": "sha512-+fdndUTwBP86cVjihTp21hZHo7d6oj1c/47XPA3lL8mM0XHs+C4EkcjmgRsFnFk2f/UONGDy9ItBItmXsLOQHw==", "dev": true, "license": "MIT", "engines": {