diff --git a/.bumpy/fix-url-no-trailing-slash-root.md b/.bumpy/fix-url-no-trailing-slash-root.md new file mode 100644 index 000000000..c3e4e9dd1 --- /dev/null +++ b/.bumpy/fix-url-no-trailing-slash-root.md @@ -0,0 +1,5 @@ +--- +varlock: patch +--- + +Allow root / with url(noTrailingSlash=true) diff --git a/packages/varlock/src/env-graph/lib/data-types.ts b/packages/varlock/src/env-graph/lib/data-types.ts index ecf7fb680..4b7dfa206 100644 --- a/packages/varlock/src/env-graph/lib/data-types.ts +++ b/packages/varlock/src/env-graph/lib/data-types.ts @@ -409,7 +409,8 @@ const UrlDataType = createEnvGraphDataType( ) { errors.push(new ValidationError(`Domain (${url.host}) is not in allowed list: ${settings.allowedDomains.join(',')}`)); } - if (settings?.noTrailingSlash && val.endsWith('/')) { + // Docs + vscode exempt root pathname `/` (https://example.com/ is OK). + if (settings?.noTrailingSlash && url.pathname.endsWith('/') && url.pathname !== '/') { errors.push(new ValidationError('URL must not have a trailing slash')); } if (settings?.matches) { diff --git a/packages/varlock/src/env-graph/test/data-types.test.ts b/packages/varlock/src/env-graph/test/data-types.test.ts index 2aac08f93..68f208f7b 100644 --- a/packages/varlock/src/env-graph/test/data-types.test.ts +++ b/packages/varlock/src/env-graph/test/data-types.test.ts @@ -82,12 +82,12 @@ describe('url data type', () => { expect(g.configSchema.MY_URL.isValid).toBe(false); }); - it('rejects bare domain with trailing slash', async () => { + it('accepts root URL with trailing slash', async () => { const g = await loadAndResolve(outdent` # @type=url(noTrailingSlash=true) MY_URL=https://example.com/ `); - expect(g.configSchema.MY_URL.isValid).toBe(false); + expect(g.configSchema.MY_URL.isValid).toBe(true); }); it('accepts bare domain without trailing slash', async () => {