Skip to content

Commit 6a94374

Browse files
authored
Merge pull request #292 from OneNoteDev/bug/embedded-youtube-with-query-parameters
Fix the embedded YouTube regular expression
2 parents 03b506b + 246125c commit 6a94374

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/scripts/domParsers/youtubeVideoExtractor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class YoutubeVideoExtractor extends VideoExtractor {
4444
}
4545

4646
if (UrlUtils.getPathname(url).indexOf("/embed") === 0) {
47-
let youTubeIdMatch = url.match(/youtube\.com\/embed\/(\S+)/);
47+
let youTubeIdMatch = url.match(/youtube\.com\/embed\/([^?|\/?]+)/);
4848
return this.createEmbeddedVideoFromId(youTubeIdMatch[1]);
4949
}
5050

src/tests/domParsers/vimeoVideoExtractor_tests.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ export class VimeoVideoExtractorTests extends TestModule {
8282
"The data original src attribute should be set to the player url");
8383
});
8484

85+
test("createEmbedVideoFromUrl should return an iframe with the src set to the player url without query parameters, and the data-original-src set to the player url", () => {
86+
let embedVideo = this.vimeoExtractor.createEmbeddedVideoFromUrl("https://vimeo.com/193851364?foo=134");
87+
strictEqual(embedVideo.src, "https://player.vimeo.com/video/193851364",
88+
"The src should be set to the player url");
89+
strictEqual(embedVideo.attributes.getNamedItem("data-original-src").value, "https://player.vimeo.com/video/193851364",
90+
"The data original src attribute should be set to the player url");
91+
});
92+
8593
test("createEmbeddedVideoFromUrl should return undefined when provided unsupported parameters for the Vimeo domain", () => {
8694
let embedVideo = this.vimeoExtractor.createEmbeddedVideoFromUrl("https://vimeo.com/ondemand/lifeanimated");
8795
strictEqual(embedVideo, undefined, "The returned iframe should be undefined");

src/tests/domParsers/youtubeVideoExtractor_tests.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export class YoutubeVideoExtractorTests extends TestModule {
3535
"https://www.youtube.com/watch?v=dQw4w9WgXcQ#foo",
3636
"https://www.youtube.com/watch?feature=youtu.be&t=30s&v=dQw4w9WgXcQ",
3737
"https://m.youtube.com/watch?v=dQw4w9WgXcQ&feature=youtu.be",
38-
"https://www.youtube.com/embed/dQw4w9WgXcQ"
38+
"https://www.youtube.com/embed/dQw4w9WgXcQ",
39+
"https://www.youtube.com/embed/dQw4w9WgXcQ/",
40+
"https://www.youtube.com/embed/dQw4w9WgXcQ?start=900"
3941
];
4042

4143
private youtubeExtractor = new YoutubeVideoExtractor();

0 commit comments

Comments
 (0)