MCPcopy Create free account
hub / github.com/WICG/webpackage / validateExchangeURL

Function validateExchangeURL

js/bundle/src/encoder.ts:269–278  ·  view source on GitHub ↗
(urlString: string)

Source from the content-addressed store, hash-verified

267// Throws an error if `urlString` is not a valid exchange URL, i.e. it must not
268// have credentials (user:password@) or hash (#fragment).
269function validateExchangeURL(urlString: string): void {
270 // `urlString` can be relative, so try parsing it with a dummy base URL.
271 const url = new URL(urlString, 'https://webbundle.example/');
272 if (url.username !== '' || url.password !== '') {
273 throw new Error('Exchange URL must not have credentials: ' + urlString);
274 }
275 if (url.hash !== '') {
276 throw new Error('Exchange URL must not have a hash: ' + urlString);
277 }
278}
279
280function byteString(s: string): Uint8Array {
281 return new TextEncoder().encode(s);

Callers 3

addExchangeMethod · 0.85
setPrimaryURLMethod · 0.85
setManifestURLMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected