diff --git a/packages/void/schema.json b/packages/void/schema.json index 684196109..03e162fb6 100644 --- a/packages/void/schema.json +++ b/packages/void/schema.json @@ -154,7 +154,7 @@ { "type": "object", "patternProperties": { - "^(/|\\*)": { + "^(\\/|\\*$)": { "type": "number", "minimum": 0 } diff --git a/packages/void/test/unit/config.test.ts b/packages/void/test/unit/config.test.ts index d41f60fb7..9446cf6a2 100644 --- a/packages/void/test/unit/config.test.ts +++ b/packages/void/test/unit/config.test.ts @@ -629,6 +629,22 @@ describe('readConfig redirects', () => { expect(new Set(schemaEnum)).toEqual(VALID_REDIRECT_STATUSES); }); + it('schema.json revalidate key pattern matches runtime validation', () => { + const schema = JSON.parse(readFileSync(join(import.meta.dirname, '../../schema.json'), 'utf8')); + const objectForm = schema.properties.routing.properties.revalidate.oneOf.find( + (s: { type?: string }) => s.type === 'object', + ); + const keyPattern = new RegExp(Object.keys(objectForm.patternProperties)[0]); + + // Runtime (config.ts) accepts a key that is exactly "*" or starts with "/". + for (const key of ['*', '/x', '/docs/*']) { + expect(keyPattern.test(key)).toBe(true); + } + for (const key of ['*foo', '**', '*/', 'foo']) { + expect(keyPattern.test(key)).toBe(false); + } + }); + it('schema.json sourceDir pattern matches runtime validation', () => { const schema = JSON.parse(readFileSync(join(import.meta.dirname, '../../schema.json'), 'utf8')); const sourceDirPattern = new RegExp(schema.properties.sourceDir.pattern);