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(meta_generator): handle multi-line head tag correctly #3778

Merged
merged 1 commit into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"after": true
}
]
},
"parserOptions": {
"ecmaVersion": 2018
}
}
2 changes: 1 addition & 1 deletion lib/plugins/filter/after_render/meta_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function hexoMetaGeneratorInject(data) {

const hexoGeneratorTag = `<meta name="generator" content="Hexo ${this.version}">`;

return data.replace(/<head>(?!<\/head>).+?<\/head>/, (str) => str.replace('</head>', `${hexoGeneratorTag}</head>`));
return data.replace(/<head>(?!<\/head>).+?<\/head>/s, (str) => str.replace('</head>', `${hexoGeneratorTag}</head>`));
}

module.exports = hexoMetaGeneratorInject;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"sinon": "^7.1.1"
},
"engines": {
"node": ">=8.6.0"
"node": ">=8.10.0"
SukkaW marked this conversation as resolved.
Show resolved Hide resolved
},
"husky": {
"hooks": {
Expand Down
14 changes: 14 additions & 0 deletions test/scripts/filters/meta_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,18 @@ describe('Meta Generator', () => {
+ '<head><link></head>';
result.should.eql(expected);
});

// Test for Issue #3777
it('multi-line head', () => {
const content = '<head>\n<link>\n</head>';
hexo.config.meta_generator = true;
const result = metaGenerator(content);

const $ = cheerio.load(result);
$('meta[name="generator"]').length.should.eql(1);

const expected = '<head>\n<link>\n<meta name="generator" content="Hexo ' + hexo.version + '"></head>';

result.should.eql(expected);
});
});