Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix and simplify media regexes #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/lib/server/media/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class GithubMediaParser {

findMediaUrls(readme: string, user: string, repo: string, branch: string): string[] {
const validGithubLinkRegex =
/https:\/\/(raw|user-images).githubusercontent.com\/[a-zA-Z0-9/]+\/[a-zA-Z0-9/\-._]+.(png|jpg|jpeg|mp4|gif)/g;
/https:\/\/(raw|user-images).githubusercontent.com\/[a-zA-Z0-9/]+\/[a-zA-Z0-9/._%+-]+.(png|jpg|jpeg|mp4|gif)/g;

const validGithubLinkMatches = readme.matchAll(validGithubLinkRegex);

Expand All @@ -39,7 +39,7 @@ export class GithubMediaParser {
}

const githubAssetRegex = new RegExp(
`https://github.com/${user}/${repo}/assets/[0-9]+/[a-zA-Z0-9-]+`,
`https://github.com/${user}/${repo}/assets/[0-9]+/[a-zA-Z0-9./_-]+`,
'g'
);

Expand All @@ -48,7 +48,7 @@ export class GithubMediaParser {
allMedia.push(asset);
}

const storedInRepoRelativeMarkdownRegex = /\(.[/a-zA-Z-_]+.(png|jpg|jpeg|mp4|gif|svg)\)/g;
const storedInRepoRelativeMarkdownRegex = /\(.[/a-zA-Z0-9._%+-]+.(png|jpg|jpeg|mp4|gif|svg)\)/g;

const relativeMarkdownMatches = readme.matchAll(storedInRepoRelativeMarkdownRegex);

Expand All @@ -64,7 +64,7 @@ export class GithubMediaParser {
}

const storedInRepoRelativeHtmlRegex =
/<img src=('|")([.][/])?[a-zA-Z-_/]+.(png|jpg|jpeg|mp4|gif|svg)('|")/g;
/<img src=['"](\.\/)?[/a-zA-Z._%+-]+.(png|jpg|jpeg|mp4|gif|svg)['"]/g;

const relativeHtmlMatches = readme.matchAll(storedInRepoRelativeHtmlRegex);

Expand Down