diff --git a/packages/docs-builder/src/parse.spec.ts b/packages/docs-builder/src/parse.spec.ts index dcb1980..48c56f6 100644 --- a/packages/docs-builder/src/parse.spec.ts +++ b/packages/docs-builder/src/parse.spec.ts @@ -182,6 +182,17 @@ Hello ) }) + it('should throw an error if a section command is used with an invalid identifier', () => { + const md = `\ + +Hello +` + const enContext = new Context(config, 'en') + expect(() => parseMarkdownPageContent(enContext, 'page_1.md', md)).toThrow( + `Identifier (foo_50_%_bar) must contain only lowercase letters, digits, and underscores (page=page_1.md)` + ) + }) + it('should throw an error if a begin-def command is not closed', () => { const md = `\ diff --git a/packages/docs-builder/src/parse.ts b/packages/docs-builder/src/parse.ts index dd0b4b3..a30804f 100644 --- a/packages/docs-builder/src/parse.ts +++ b/packages/docs-builder/src/parse.ts @@ -173,7 +173,11 @@ function parseCommand(context: Context, token: marked.Token): Command | undefine return undefined } - const m = raw.match(//) + // Note: the identifier is captured as a run of non-whitespace characters (rather + // than `\w+`) so that an id containing invalid characters (e.g. `%`) is still + // captured here and caught by the validation below, instead of causing the whole + // match to fail and the command to be silently ignored + const m = raw.match(//) if (!m) { return undefined }