jonschlinkert/gray-matter

Identical calls to `matter` should produce the same result

movermeyer opened this issue · 1 comments

Identical, successive calls to matter return different results.

Example code:

const input = `---
foo: bar
---
Tada!`;

const parsed = matter(contents);
const parsed_again = matter(contents);
console.log(parsed.language) // => yaml
console.log(parsed_again.language) // => undefined

I understand from this comment that it's caching based on the input string, and I can cache bust by passing in an empty options hash as a workaround.

In this case, I'm fine with it caching (even though it was unexpected and IMO should at least be documented). However, the cache should cache the resulting object exactly, so that identical calls to matter always return the same result.

It's seems that the results are cached based on the content after frontmatter only, and not the whole content string. Which is even weirder. This means that when it first parses this:

# Some title

Some content

it will return {}, but when it then parses this:

---
abc: 123
---
# Some title

Some content

it returns cached {}...