Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid front-matter should not be cached #166

Open
Fil opened this issue Nov 27, 2023 · 0 comments
Open

Invalid front-matter should not be cached #166

Fil opened this issue Nov 27, 2023 · 0 comments

Comments

@Fil
Copy link

Fil commented Nov 27, 2023

In case of an error, the result should not be cached. Currently the second call with the same invalid contents returns a (wrong) value.

❯ node
Welcome to Node.js v20.3.0.
Type ".help" for more information.
> const matter = require('gray-matter');
undefined
> matter("---\n{}+\n---\n")
Uncaught:
YAMLException: end of the stream or a document separator is expected at line 2, column 3:
    {}+
      ^
    at generateError (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:167:10)
    at throwError (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:173:9)
    at readDocument (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:1545:5)
    at loadDocuments (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:1588:5)
    at load (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:1614:19)
    at Object.safeLoad (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:1637:10)
    at module.exports (node_modules/gray-matter/lib/parse.js:12:17)
    at parseMatter (node_modules/gray-matter/index.js:109:17)
    at matter (node_modules/gray-matter/index.js:50:10) {
  reason: 'end of the stream or a document separator is expected',
  mark: Mark {
    name: null,
    buffer: '\n{}+\n\x00',
    position: 3,
    line: 1,
    column: 2
  }
}
> matter("---\n{}+\n---\n")
{
  content: '---\n{}+\n---\n',
  data: {},
  isEmpty: false,
  excerpt: '',
  orig: <Buffer 2d 2d 2d 0a 7b 7d 2b 0a 2d 2d 2d 0a>
}
Fil added a commit to observablehq/framework that referenced this issue Nov 30, 2023
Use an object config to skip gray-matter's caching (see jonschlinkert/gray-matter#166)
closes #215
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant