Skip to content

Commit

Permalink
fix youtube channel link parsing regex not correctly parsing handles …
Browse files Browse the repository at this point in the history
…with periods (#1448)
  • Loading branch information
dyc3 authored Mar 5, 2024
1 parent 93c8691 commit 56263f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/services/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ export default class YouTubeAdapter extends ServiceAdapter {
}

getChannelId(url: URL): YoutubeChannelData {
const match = /\/(?!(?:c(?:hannel)?|user)\/)(@?[a-z0-9_-]+)/gi.exec(url.pathname);
const match = /\/(?!(?:c(?:hannel)?|user)\/)(@?[.a-z0-9_-]+)/gi.exec(url.pathname);
if (match === null) {
throw new OttException("Invalid channel url");
}
Expand Down
5 changes: 5 additions & 0 deletions server/tests/unit/services/youtube.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const validCollectionLinks = [
"https://www.youtube.com/watch?v=0hasodi12&list=9asdouihlj1293gashd",
"https://youtu.be/3kw2_89ym31W?list=PL4d83g68ij3l45kj6345hFaEHvzLovtb",
"https://youtube.com/@handle",
"https://youtube.com/@handle.foo",
];

const FIXTURE_DIRECTORY = "./tests/unit/fixtures/services/youtube";
Expand Down Expand Up @@ -547,7 +548,11 @@ describe("Youtube", () => {
describe("getChannelId", () => {
it.each([
["https://youtube.com/@rollthedyc3", { handle: "@rollthedyc3" }],
["https://youtube.com/@rollthedyc3/videos", { handle: "@rollthedyc3" }],
["https://youtube.com/@rollthedyc3.123", { handle: "@rollthedyc3.123" }],
["https://youtube.com/@rollthedyc3.123/videos", { handle: "@rollthedyc3.123" }],
["https://youtube.com/user/vinesauce", { user: "vinesauce" }],
["https://youtube.com/user/vinesauce/videos", { user: "vinesauce" }],
[
"https://youtube.com/channel/UCI1XS_GkLGDOgf8YLaaXNRA",
{ channel: "UCI1XS_GkLGDOgf8YLaaXNRA" },
Expand Down

0 comments on commit 56263f9

Please sign in to comment.