Skip to content

Commit 865acec

Browse files
🐛 Koenig - Support schema-less URLs in embed card (#9725)
refs #9724 - adjust the "base url" regex in the oembed endpoint to strip schemaless scheme `//` as well as `https?://`
1 parent 3ec6249 commit 865acec

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

core/server/api/oembed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let oembed = {
1414

1515
// build up a list of URL variations to test against because the oembed
1616
// providers list is not always up to date with scheme or www vs non-www
17-
let base = url.replace(/https?:\/\/(?:www\.)?/, '');
17+
let base = url.replace(/^\/\/|^https?:\/\/(?:www\.)?/, '');
1818
let testUrls = [
1919
`http://${base}`,
2020
`https://${base}`,

core/test/unit/api/oembed_spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ describe('API: oembed', function () {
2222
}).catch(done);
2323
});
2424

25+
it('finds match for schema-less urls', function (done) {
26+
let requestMock = nock('https://www.reddit.com')
27+
.get('/oembed')
28+
.query(true)
29+
.reply(200, {
30+
html: 'test'
31+
});
32+
33+
OembedAPI.read({url: '//www.reddit.com/r/pics/comments/8qi5oq/breathtaking_picture_of_jupiter_with_its_moon_io/'})
34+
.then((results) => {
35+
requestMock.isDone().should.be.true;
36+
should.exist(results);
37+
should.exist(results.html);
38+
done();
39+
}).catch(done);
40+
});
41+
2542
it('returns error for missing url', function (done) {
2643
OembedAPI.read({url: ''})
2744
.then(() => {

0 commit comments

Comments
 (0)