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

fix(#4917): suppress YAMLException when load js-yaml #4927

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(#4917): suppress YAMLException when load js-yaml
* it is just a workaround
yoshinorin committed Apr 2, 2022
commit 610bf40b24a63461e727c234d02e7bc35fe9328d
14 changes: 13 additions & 1 deletion lib/plugins/renderer/yaml.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,19 @@

const yaml = require('js-yaml');
const { escape } = require('hexo-front-matter');
const schema = yaml.DEFAULT_SCHEMA.extend(require('js-yaml-js-types').all);
const log = require('hexo-log')();

let schema = {};
// FIXME: workaround for https://github.com/hexojs/hexo/issues/4917
try {
schema = yaml.DEFAULT_SCHEMA.extend(require('js-yaml-js-types').all);
} catch (e) {
if (e instanceof yaml.YAMLException) {
log.warn('YAMLException: please see https://github.com/hexojs/hexo/issues/4917');
} else {
throw e;
}
}

function yamlHelper(data) {
return yaml.load(escape(data.text), { schema });