feat: allow numbers in plugin ID (#6656)

* fix example for id that didn't respect regex

example for id don't work with version 2.0.0-beta.15:
ValidationError: "id" with value "docs1" fails to match the required pattern: /^[a-zA-Z_-]+$/
Error: Process completed with exit code 1.

* properly fix

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
Clement Demonchy 2022-02-11 04:57:58 +01:00 committed by GitHub
parent 10a5f71154
commit 1cd4757828
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View file

@ -12,13 +12,13 @@ exports[`validation schemas PathnameSchema: for value="foo" 1`] = `"\\"value\\"
exports[`validation schemas PathnameSchema: for value="https://github.com/foo" 1`] = `"\\"value\\" is not a valid pathname. Pathname should start with slash and not contain any domain or query string."`;
exports[`validation schemas PluginIdSchema: for value="/docs" 1`] = `"\\"value\\" with value \\"/docs\\" fails to match the required pattern: /^[a-zA-Z_-]+$/"`;
exports[`validation schemas PluginIdSchema: for value="/docs" 1`] = `"Illegal plugin ID value \\"/docs\\": it should only contain alphanumerics, underscores, and dashes."`;
exports[`validation schemas PluginIdSchema: for value="do cs" 1`] = `"\\"value\\" with value \\"do cs\\" fails to match the required pattern: /^[a-zA-Z_-]+$/"`;
exports[`validation schemas PluginIdSchema: for value="do cs" 1`] = `"Illegal plugin ID value \\"do cs\\": it should only contain alphanumerics, underscores, and dashes."`;
exports[`validation schemas PluginIdSchema: for value="do/cs" 1`] = `"\\"value\\" with value \\"do/cs\\" fails to match the required pattern: /^[a-zA-Z_-]+$/"`;
exports[`validation schemas PluginIdSchema: for value="do/cs" 1`] = `"Illegal plugin ID value \\"do/cs\\": it should only contain alphanumerics, underscores, and dashes."`;
exports[`validation schemas PluginIdSchema: for value="docs/" 1`] = `"\\"value\\" with value \\"docs/\\" fails to match the required pattern: /^[a-zA-Z_-]+$/"`;
exports[`validation schemas PluginIdSchema: for value="docs/" 1`] = `"Illegal plugin ID value \\"docs/\\": it should only contain alphanumerics, underscores, and dashes."`;
exports[`validation schemas PluginIdSchema: for value=[] 1`] = `"\\"value\\" must be a string"`;

View file

@ -69,6 +69,7 @@ describe('validation schemas', () => {
testOK('docs');
testOK('default');
testOK('plugin-id_with-simple-special-chars');
testOK('doc1');
testFail('/docs');
testFail('docs/');

View file

@ -11,7 +11,10 @@ import type {Tag} from '@docusaurus/utils';
import {JoiFrontMatter} from './JoiFrontMatter';
export const PluginIdSchema = Joi.string()
.regex(/^[a-zA-Z_-]+$/)
.regex(/^[a-zA-Z0-9_-]+$/)
.message(
'Illegal plugin ID value "{#value}": it should only contain alphanumerics, underscores, and dashes.',
)
.default(DEFAULT_PLUGIN_ID);
const MarkdownPluginsSchema = Joi.array()