Skip to content

Commit

Permalink
fix: Add regex check for parsing TS mod string (#421)
Browse files Browse the repository at this point in the history
Otherwise we accept improper formatted Thunderstore mod strings like
`AUTHOR-MOD-VERSION-RANDOM_STUFF`
  • Loading branch information
GeckoEidechse authored Jul 17, 2023
1 parent 5d679ca commit 605d7a1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src-tauri/src/mod_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ impl std::str::FromStr for ParsedThunderstoreModString {
type Err = &'static str; // todo use an better error management

fn from_str(s: &str) -> Result<Self, Self::Err> {
// Check whether Thunderstore string passse reges
let re = regex::Regex::new(r"^[a-zA-Z0-9_]+-[a-zA-Z0-9_]+-\d+\.\d+\.\d++$").unwrap();
if !re.is_match(s) {
return Err("Incorrect format");
}

let mut parts = s.split('-');

let author_name = parts.next().ok_or("None value on author_name")?.to_string();
Expand Down

0 comments on commit 605d7a1

Please sign in to comment.