Skip to content

Commit

Permalink
fix: spm backend doesn't allow a GitHub repo name containing a dot (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
roele authored Aug 11, 2024
1 parent 7ef1949 commit 062b6e3
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/backend/spm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,11 @@ struct SwiftPackageRepo {
}

impl SwiftPackageRepo {
/// Parse the slug or the full URL of a GitHub package repository.
fn new(name: &str) -> Result<Self, eyre::Error> {
let shorthand_regex = regex!(r"^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$");
let shorthand_regex = regex!(r"^[a-zA-Z0-9_-]+/[a-zA-Z0-9._-]+$");
let shorthand_in_url_regex =
regex!(r"https://github.com/([a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+)\.git");
regex!(r"https://github.com/([a-zA-Z0-9_-]+/[a-zA-Z0-9._-]+)\.git");

let shorthand = if let Some(Some(m)) =
shorthand_in_url_regex.captures(name).map(|c| c.get(1))
Expand Down Expand Up @@ -260,6 +261,27 @@ mod tests {
assert_str_eq!(package_repo.shorthand, "nicklockwood/SwiftFormat");
}

#[test]
fn test_spm_repo_init_name() {
reset();
assert!(
SwiftPackageRepo::new("owner/name.swift").is_ok(),
"name part can contain ."
);
assert!(
SwiftPackageRepo::new("owner/name_swift").is_ok(),
"name part can contain _"
);
assert!(
SwiftPackageRepo::new("owner/name-swift").is_ok(),
"name part can contain -"
);
assert!(
SwiftPackageRepo::new("owner/name$swift").is_err(),
"name part cannot contain characters other than a-zA-Z0-9._-"
);
}

#[test]
fn test_spm_repo_init_by_url() {
reset();
Expand Down

0 comments on commit 062b6e3

Please sign in to comment.