0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🐛 Fixed pasting product URLs into the editor (#20565)

fixes https://linear.app/tryghost/issue/ENG-1215

- when pasting URLs that return `type: link` from the oembed service, we
now fallback to using a Bookmark card
- previously, this would render a plain link in the editor
- example product URL with `type: link`:
https://indiebeer.co.uk/products/terra-tempo-vinicius-red-wine-ba-wild-ale-with-mango-pineapple-honeydew-melon-and-banana-750ml-7
This commit is contained in:
Sag 2024-07-09 18:28:56 +02:00 committed by GitHub
parent 00230314db
commit d0d0783837
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 3 deletions

View file

@ -260,7 +260,7 @@ describe('Oembed API', function () {
const pageMock = nock('http://oembed.test.com') const pageMock = nock('http://oembed.test.com')
.get('/') .get('/')
.reply(200, '<html><head><link rel="alternate" type="application/json+oembed" href="http://oembed.test.com/my-embed"></head></html>'); .reply(200, '<html><head><link rel="alternate" type="application/json+oembed" href="http://oembed.test.com/my-embed"><title>Title</title></head></html>');
const oembedMock = nock('http://oembed.test.com') const oembedMock = nock('http://oembed.test.com')
.get('/my-embed') .get('/my-embed')
@ -284,7 +284,7 @@ describe('Oembed API', function () {
it('fetches url and follows <link rel="alternate">', async function () { it('fetches url and follows <link rel="alternate">', async function () {
const pageMock = nock('http://test.com') const pageMock = nock('http://test.com')
.get('/') .get('/')
.reply(200, '<html><head><link rel="alternate" type="application/json+oembed" href="http://test.com/oembed"></head></html>'); .reply(200, '<html><head><link rel="alternate" type="application/json+oembed" href="http://test.com/oembed"><title>Title</title></head></html>');
const oembedMock = nock('http://test.com') const oembedMock = nock('http://test.com')
.get('/oembed') .get('/oembed')
@ -307,7 +307,7 @@ describe('Oembed API', function () {
it('follows redirects when fetching <link rel="alternate">', async function () { it('follows redirects when fetching <link rel="alternate">', async function () {
const pageMock = nock('http://test.com') const pageMock = nock('http://test.com')
.get('/') .get('/')
.reply(200, '<html><head><link rel="alternate" type="application/json+oembed" href="http://test.com/oembed"></head></html>'); .reply(200, '<html><head><link rel="alternate" type="application/json+oembed" href="http://test.com/oembed"><title>Title</title></head></html>');
const alternateRedirectMock = nock('http://test.com') const alternateRedirectMock = nock('http://test.com')
.get('/oembed') .get('/oembed')

View file

@ -340,6 +340,11 @@ class OEmbedService {
]; ];
const oembed = _.pick(body, knownFields); const oembed = _.pick(body, knownFields);
// Fallback to bookmark if it's a link type
if (oembed.type === 'link') {
return;
}
// ensure we have required data for certain types // ensure we have required data for certain types
if (oembed.type === 'photo' && !oembed.url) { if (oembed.type === 'photo' && !oembed.url) {
return; return;

View file

@ -146,5 +146,31 @@ describe('oembed-service', function () {
assert.equal(response.url, 'https://www.example.com'); assert.equal(response.url, 'https://www.example.com');
assert.equal(response.metadata.title, 'Example'); assert.equal(response.metadata.title, 'Example');
}); });
it('should return a bookmark response when the oembed endpoint returns a link type', async function () {
nock('https://www.example.com')
.get('/')
.query(true)
.reply(200, `<html><head><link type="application/json+oembed" href="https://www.example.com/oembed"><title>Example</title></head></html>`);
nock('https://www.example.com')
.get('/oembed')
.query(true)
.reply(200, {
type: 'link',
version: '1.0',
title: 'Test Title',
author_name: 'Test Author',
author_url: 'https://example.com/user/testauthor',
url: 'https://www.example.com'
});
const response = await oembedService.fetchOembedDataFromUrl('https://www.example.com');
assert.equal(response.version, '1.0');
assert.equal(response.type, 'bookmark');
assert.equal(response.url, 'https://www.example.com');
assert.equal(response.metadata.title, 'Example');
});
}); });
}); });