mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-02-04 07:13:25 +08:00
Disallow leading whitespace before delimiter
This commit is contained in:
parent
70f024735b
commit
a11ab3d5ea
@ -41,6 +41,13 @@ describe('extractFrontmatter', () => {
|
|||||||
expect(db.setDiagramTitle).toHaveBeenCalledWith('foo---bar');
|
expect(db.setDiagramTitle).toHaveBeenCalledWith('foo---bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles frontmatter with multi-line string and multiple delimiters', () => {
|
||||||
|
const db = dbMock();
|
||||||
|
const text = `---\ntitle: |\n multi-line string\n ---\n---\ndiagram`;
|
||||||
|
expect(extractFrontMatter(text, db)).toEqual('diagram');
|
||||||
|
expect(db.setDiagramTitle).toHaveBeenCalledWith('multi-line string\n---\n');
|
||||||
|
});
|
||||||
|
|
||||||
it('handles frontmatter with title', () => {
|
it('handles frontmatter with title', () => {
|
||||||
const db = dbMock();
|
const db = dbMock();
|
||||||
const text = `---\ntitle: foo\n---\ndiagram`;
|
const text = `---\ntitle: foo\n---\ndiagram`;
|
||||||
|
@ -6,7 +6,7 @@ import * as yaml from 'js-yaml';
|
|||||||
// Note that JS doesn't support the "\A" anchor, which means we can't use
|
// Note that JS doesn't support the "\A" anchor, which means we can't use
|
||||||
// multiline mode.
|
// multiline mode.
|
||||||
// Relevant YAML spec: https://yaml.org/spec/1.2.2/#914-explicit-documents
|
// Relevant YAML spec: https://yaml.org/spec/1.2.2/#914-explicit-documents
|
||||||
export const frontMatterRegex = /^(?:\s*---\s*[\r\n])(.*?)(?:[\r\n]\s*---\s*[\r\n]+)/s;
|
export const frontMatterRegex = /^(?:---\s*[\r\n])(.*?)(?:[\r\n]---\s*[\r\n]+)/s;
|
||||||
|
|
||||||
type FrontMatterMetadata = {
|
type FrontMatterMetadata = {
|
||||||
title?: string;
|
title?: string;
|
||||||
|
@ -238,10 +238,9 @@ Alice->Bob: hi`;
|
|||||||
const type = detectType(str);
|
const type = detectType(str);
|
||||||
expect(type).toBe('gitGraph');
|
expect(type).toBe('gitGraph');
|
||||||
});
|
});
|
||||||
it('should handle frontmatter with leading spaces', function () {
|
it('should not allow frontmatter with leading spaces', function () {
|
||||||
const str = ' ---\ntitle: foo\n---\n gitGraph TB:\nbfs1:queue';
|
const str = ' ---\ntitle: foo\n---\n gitGraph TB:\nbfs1:queue';
|
||||||
const type = detectType(str);
|
expect(() => detectType(str)).toThrow('No diagram type detected for text');
|
||||||
expect(type).toBe('gitGraph');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when finding substring in array ', function () {
|
describe('when finding substring in array ', function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user