Skip to content

Commit

Permalink
Merge pull request #103 from radiovisual/invalid-url-handling
Browse files Browse the repository at this point in the history
Fix: incomplete iframe src url throws error
  • Loading branch information
radiovisual authored Aug 19, 2022
2 parents 1d5667d + 75af5cc commit 65c082c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ test('returns null as id and service', () => {
service: null,
};
expect(fn('foo')).toMatchObject(expected);
expect(fn('<iframe')).toMatchObject(expected);
expect(fn('')).toMatchObject(expected);
});
1 change: 1 addition & 0 deletions __tests__/utils/get-src.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('get-src', () => {

test('returns undefined when no src= is found', () => {
expect(fn('hello')).toBe(undefined);
expect(fn('<iframe')).toBe(undefined);
});

test('single quotes return undefined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getVideoId(urlString) {
let string_ = urlString;

if (/<iframe/gi.test(string_)) {
string_ = getSrc(string_);
string_ = getSrc(string_) || '';
}

// Remove surrounding whitespaces or linefeeds
Expand Down

0 comments on commit 65c082c

Please sign in to comment.