mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-17 05:00:26 +00:00
Only allow true Github links to be checked through the Github API (#201)
This commit is contained in:
parent
036145eb98
commit
97aaadf97c
1 changed files with 24 additions and 3 deletions
|
|
@ -263,10 +263,10 @@ impl Client {
|
|||
}
|
||||
|
||||
fn extract_github(&self, url: &str) -> Result<(String, String)> {
|
||||
let re = Regex::new(r"github\.com/([^/]*)/([^/]*)")?;
|
||||
let re = Regex::new(r#"^(https?://)?(www.)?github.com/(?P<owner>[^/]*)/(?P<repo>[^/]*)"#)?;
|
||||
let caps = re.captures(&url).context("Invalid capture")?;
|
||||
let owner = caps.get(1).context("Cannot capture owner")?;
|
||||
let repo = caps.get(2).context("Cannot capture repo")?;
|
||||
let owner = caps.name("owner").context("Cannot capture owner")?;
|
||||
let repo = caps.name("repo").context("Cannot capture repo")?;
|
||||
Ok((owner.as_str().into(), repo.as_str().into()))
|
||||
}
|
||||
|
||||
|
|
@ -358,6 +358,22 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_is_github() {
|
||||
assert_eq!(
|
||||
ClientBuilder::default()
|
||||
.build()
|
||||
.unwrap()
|
||||
.extract_github("github.com/lycheeverse/lychee")
|
||||
.unwrap(),
|
||||
("lycheeverse".into(), "lychee".into())
|
||||
);
|
||||
assert_eq!(
|
||||
ClientBuilder::default()
|
||||
.build()
|
||||
.unwrap()
|
||||
.extract_github("www.github.com/lycheeverse/lychee")
|
||||
.unwrap(),
|
||||
("lycheeverse".into(), "lychee".into())
|
||||
);
|
||||
assert_eq!(
|
||||
ClientBuilder::default()
|
||||
.build()
|
||||
|
|
@ -366,6 +382,11 @@ mod test {
|
|||
.unwrap(),
|
||||
("lycheeverse".into(), "lychee".into())
|
||||
);
|
||||
assert!(ClientBuilder::default()
|
||||
.build()
|
||||
.unwrap()
|
||||
.extract_github("https://pkg.go.dev/github.com/Debian/pkg-go-tools/cmd/pgt-gopath")
|
||||
.is_err());
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn test_github() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue