diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index e581e8d5dcabcc0c6ad961dfc430393ab2623f66..eae7c46607c25fdb26ffe358ec883b6ff9f91b2e 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -1206,6 +1206,10 @@ If the value starts with `http(s)` then it will only match against URLs which st Otherwise, it will be matched by checking if the URL's hostname matches the `matchHost` directly or ends with it. When checking the end of the hostname, a single dot is prefixed to the value of `matchHost`, if one is not already present, to ensure it can only match against whole domain segments. +<!-- prettier-ignore --> +!!! note + Values containing a URL path but missing a scheme will be prepended with 'https://' (e.g. `domain.com/path` -> `https://domain.com/path`) + ### timeout Use this figure to adjust the timeout for queries. diff --git a/lib/config/migrations/custom/host-rules-migration.spec.ts b/lib/config/migrations/custom/host-rules-migration.spec.ts index f1a7bca461724bc9a0aeb48b5b7a63bcdeec556f..fe399a79db42eba5eca7b08019ca7adf5b7b6eb8 100644 --- a/lib/config/migrations/custom/host-rules-migration.spec.ts +++ b/lib/config/migrations/custom/host-rules-migration.spec.ts @@ -7,6 +7,8 @@ describe('config/migrations/custom/host-rules-migration', () => { hostRules: [ { baseUrl: 'https://some.domain.com', token: '123test' }, { domainName: 'domain.com', token: '123test' }, + { domainName: 'domain.com/', token: '123test' }, + { matchHost: 'domain.com/', token: '123test' }, { hostName: 'some.domain.com', token: '123test' }, ], } as any, @@ -14,6 +16,8 @@ describe('config/migrations/custom/host-rules-migration', () => { hostRules: [ { matchHost: 'https://some.domain.com', token: '123test' }, { matchHost: 'domain.com', token: '123test' }, + { matchHost: 'https://domain.com/', token: '123test' }, + { matchHost: 'https://domain.com/', token: '123test' }, { matchHost: 'some.domain.com', token: '123test' }, ], } diff --git a/lib/config/migrations/custom/host-rules-migration.ts b/lib/config/migrations/custom/host-rules-migration.ts index 6c3be00e0d8afab0c9d9e1bdca225a59792ba1da..45bd9f13f512040a34085424b32f1e002ebf329d 100644 --- a/lib/config/migrations/custom/host-rules-migration.ts +++ b/lib/config/migrations/custom/host-rules-migration.ts @@ -6,10 +6,11 @@ export class HostRulesMigration extends AbstractMigration { override readonly propertyName = 'hostRules'; override run(value: Record<string, unknown>[]): void { - const newHostRules: HostRule[] = value.map((rule) => { + const newHostRules: HostRule[] = []; + for (const hostRule of value) { const newRule: any = {}; - for (const [key, value] of Object.entries(rule)) { + for (const [key, value] of Object.entries(hostRule)) { if (key === 'platform') { if (is.string(value)) { newRule.hostType ??= value; @@ -17,6 +18,13 @@ export class HostRulesMigration extends AbstractMigration { continue; } + if (key === 'matchHost') { + if (is.string(value)) { + newRule.matchHost ??= massageUrl(value); + } + continue; + } + if ( key === 'endpoint' || key === 'host' || @@ -25,7 +33,7 @@ export class HostRulesMigration extends AbstractMigration { key === 'domainName' ) { if (is.string(value)) { - newRule.matchHost ??= value; + newRule.matchHost ??= massageUrl(value); } continue; } @@ -33,9 +41,17 @@ export class HostRulesMigration extends AbstractMigration { newRule[key] = value; } - return newRule; - }); + newHostRules.push(newRule); + } this.rewrite(newHostRules); } } + +function massageUrl(url: string): string { + if (!url.includes('://') && url.includes('/')) { + return 'https://' + url; + } else { + return url; + } +}