Fix: not greedy match the frontmatter in postcss parser (#4457)

master
Elias Meire 2018-05-10 18:50:19 +02:00 committed by Lucas Duailibe
parent b504e79113
commit 2f5c00ad18
3 changed files with 41 additions and 1 deletions

View File

@ -439,7 +439,7 @@ function parseNestedCSS(node) {
function parseWithParser(parser, text) {
let result;
const frontMatterMatches = text.match(/^---(\n[\s\S]*)?\n---/);
const frontMatterMatches = text.match(/^---(\n[\s\S]*?)?\n---/);
const frontMatter = frontMatterMatches && frontMatterMatches[0];
const normalizedText = frontMatter ? text.substr(frontMatter.length) : text;

View File

@ -53,6 +53,33 @@ a {
`;
exports[`malformed-2.css 1`] = `
---
foo: bar
---
a {
color:blue
}
---
.b {
color:red
}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
foo: bar
---
a {
color: blue;
}
--- .b {
color: red;
}
`;
exports[`only_comments.css 1`] = `
---
# comment 1

View File

@ -0,0 +1,13 @@
---
foo: bar
---
a {
color:blue
}
---
.b {
color:red
}