Skip to content

Commit 06a8ebb

Browse files
fix(#5053): exclude data-uri image for og:image (#5053)
1 parent 6deeb8d commit 06a8ebb

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/plugins/helper/open_graph.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ function openGraphHelper(options = {}) {
115115
result += og('og:locale', localeToTerritory(language), false);
116116
}
117117

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

120121
images.forEach(path => {
121122
result += og('og:image', path, false);

test/scripts/helpers/open_graph.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ describe('open_graph', () => {
211211
result.should.have.string(meta({property: 'og:image', content: 'https://hexo.io/test.jpg'}));
212212
});
213213

214+
it('images - content with data-uri', () => {
215+
const result = openGraph.call({
216+
page: {
217+
content: '<img src="data:image/svg+xml;utf8,<svg>...</svg>">'
218+
},
219+
config: hexo.config,
220+
is_post: isPost
221+
});
222+
223+
result.should.not.have.string(meta({property: 'og:image', content: 'data:image/svg+xml;utf8,<svg>...</svg>'}));
224+
});
225+
214226
it('images - string', () => {
215227
const result = openGraph.call({
216228
page: {

0 commit comments

Comments
 (0)