jxson / front-matter

Extract YAML front matter from strings
MIT License
676 stars 76 forks source link

Spaces after yaml document start cause parse failure #53

Open jayvdb opened 7 years ago

jayvdb commented 7 years ago

YAML spec allows spaces after the ---

The regex used by this package prevents that.

wild-flame commented 6 years ago

I too encounterd with this problem

This can be fixed be changing var pattern to

var pattern = '^(' +
  optionalByteOrderMark +
  '(= yaml =|---)' +
  '$([\\s\\S]*?)' +
  '^(?:\\2|\\.\\.\\.)\\s*' +
  '$' +
  (process.platform === 'win32' ? '\\r?' : '') +
  '(?:\\n)?)'
gr2m commented 2 months ago

Hello from @github 👋🏼 The blog team is using this library, thank you so much!

Just wondering if you'd accept a pull request that fixes it? I can't promise when but I'd be happy to submit one, or try to find someone else you would.

jayvdb commented 2 months ago

Probably was fixed by https://github.com/jxson/front-matter/pull/54

gr2m commented 2 months ago

We ran into it today, using the latest version (4.0.2), so I think it's not quite fixed?

gr2m commented 2 months ago

Here is a test case to reproduce the problem

const frontMatter = require("front-matter"); // v4.0.2

const markdownContent = `---  
foo: bar
---

content`;

console.log(frontMatter(markdownContent));

// {
//   attributes: {},
//   body: '---  \nfoo: bar\n---\n\ncontent',
//   bodyBegin: 1
// }
jxson commented 2 months ago

Hi @gr2m,

I'll definitely take pull requests, especially if it includes a test ;)