Skip to content

Commit

Permalink
fix(#5053): exclude data-uri image for og:image (#5053)
Browse files Browse the repository at this point in the history
  • Loading branch information
KentarouTakeda authored Sep 7, 2022
1 parent 6deeb8d commit 06a8ebb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/plugins/helper/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ function openGraphHelper(options = {}) {
result += og('og:locale', localeToTerritory(language), false);
}

images = images.map(path => new URL(path, url || config.url).toString());
images = images.map(path => new URL(path, url || config.url).toString())
.filter(url => !url.startsWith('data:'));

images.forEach(path => {
result += og('og:image', path, false);
Expand Down
12 changes: 12 additions & 0 deletions test/scripts/helpers/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ describe('open_graph', () => {
result.should.have.string(meta({property: 'og:image', content: 'https://hexo.io/test.jpg'}));
});

it('images - content with data-uri', () => {
const result = openGraph.call({
page: {
content: '<img src="data:image/svg+xml;utf8,<svg>...</svg>">'
},
config: hexo.config,
is_post: isPost
});

result.should.not.have.string(meta({property: 'og:image', content: 'data:image/svg+xml;utf8,<svg>...</svg>'}));
});

it('images - string', () => {
const result = openGraph.call({
page: {
Expand Down

0 comments on commit 06a8ebb

Please sign in to comment.