Skip to content

Commit

Permalink
🐛 Koenig - Support schema-less URLs in embed card (#9725)
Browse files Browse the repository at this point in the history
refs #9724
- adjust the "base url" regex in the oembed endpoint to strip schemaless scheme `//` as well as `https?://`
  • Loading branch information
kevinansfield authored Jul 9, 2018
1 parent 3ec6249 commit 865acec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/server/api/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let oembed = {

// build up a list of URL variations to test against because the oembed
// providers list is not always up to date with scheme or www vs non-www
let base = url.replace(/https?:\/\/(?:www\.)?/, '');
let base = url.replace(/^\/\/|^https?:\/\/(?:www\.)?/, '');
let testUrls = [
`http://${base}`,
`https://${base}`,
Expand Down
17 changes: 17 additions & 0 deletions core/test/unit/api/oembed_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ describe('API: oembed', function () {
}).catch(done);
});

it('finds match for schema-less urls', function (done) {
let requestMock = nock('https://www.reddit.com')
.get('/oembed')
.query(true)
.reply(200, {
html: 'test'
});

OembedAPI.read({url: '//www.reddit.com/r/pics/comments/8qi5oq/breathtaking_picture_of_jupiter_with_its_moon_io/'})
.then((results) => {
requestMock.isDone().should.be.true;
should.exist(results);
should.exist(results.html);
done();
}).catch(done);
});

it('returns error for missing url', function (done) {
OembedAPI.read({url: ''})
.then(() => {
Expand Down

0 comments on commit 865acec

Please sign in to comment.