Skip to content

Commit

Permalink
fix(meta_generator): avoid an edge case (#4017)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW authored Dec 30, 2019
1 parent f332669 commit ffa0648
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
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 @@ -3,7 +3,7 @@
function hexoMetaGeneratorInject(data) {
const { config } = this;
if (!config.meta_generator
|| data.match(/<meta\s+name=['|"]?generator['|"]?/i)) return;
|| data.match(/<meta([\s]+|[\s]+[^<>]+[\s]+)name=['|"]?generator['|"]?/i)) return;

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

Expand Down
8 changes: 3 additions & 5 deletions test/scripts/filters/meta_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ describe('Meta Generator', () => {
});

it('no duplicate generator tag', () => {
const content = '<head><link>'
+ '<meta name="generator" content="foo"></head>';
hexo.config.meta_generator = true;
const result = metaGenerator(content);
const resultType = str => typeof metaGenerator(str);

const resultType = typeof result;
resultType.should.eql('undefined');
resultType('<head><link><meta name="generator" content="foo"></head>').should.eql('undefined');
resultType('<head><link><meta content="foo" name="generator"></head>').should.eql('undefined');
});

it('ignore empty head tag', () => {
Expand Down

0 comments on commit ffa0648

Please sign in to comment.