simplify diff

This commit is contained in:
Olivier Chafik 2025-06-16 23:10:27 +01:00
commit 02ce81b90c
No known key found for this signature in database

View file

@ -1,5 +1,5 @@
/**
* Utilities for handling OAuth resource URIs according to RFC 8707.
* Utilities for handling OAuth resource URIs.
*/
/**
@ -7,27 +7,8 @@
* RFC 8707 section 2 states that resource URIs "MUST NOT include a fragment component".
* Keeps everything else unchanged (scheme, domain, port, path, query).
*/
export function resourceUrlFromServerUrl(url: string): string {
const hashIndex = url.indexOf('#');
return hashIndex === -1 ? url : url.substring(0, hashIndex);
export function resourceUrlFromServerUrl(url: URL): URL {
const resourceURL = new URL(url.href);
resourceURL.hash = ''; // Remove fragment
return resourceURL;
}
/**
* Validates a resource URI according to RFC 8707 requirements.
* @param resourceUri The resource URI to validate
* @throws Error if the URI contains a fragment
*/
export function validateResourceUri(resourceUri: string): void {
if (resourceUri.includes('#')) {
throw new Error(`Invalid resource URI: ${resourceUri} - must not contain a fragment`);
}
}
/**
* Extracts resource URI from server URL by removing fragment.
* @param serverUrl The server URL to extract from
* @returns The resource URI without fragment
*/
export function extractResourceUri(serverUrl: string | URL): string {
return resourceUrlFromServerUrl(typeof serverUrl === 'string' ? serverUrl : serverUrl.href);
}