Skip to content

Commit

Permalink
Fix parse fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
jssblck committed May 18, 2024
1 parent 6861bde commit 3ccfee0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,13 +593,12 @@ mod tests {

/// Regular expression that matches any unicode string that is:
/// - Prefixed with `git+`
/// - Contains a literal `/`
/// - Contains zero or more digits
/// - Contains a literal `/`
/// - Contains at least one character that is not a control character and not the literal `$`
/// - Contains a literal `$`
/// - Contains at least one character that is not a control character and not the literal `$`
const VALID_INPUTS_GIT_WITH_ORG: &str = r"git\+/\d*/[^\pC$]+\$[^\pC$]+";
const VALID_INPUTS_GIT_WITH_ORG: &str = r"git\+\d*/[^\pC$]+\$[^\pC$]+";

proptest! {
/// Tests randomly generated strings that match the provided regular expression against the parser.
Expand Down Expand Up @@ -630,13 +629,12 @@ mod tests {

/// Regular expression that matches any unicode string that is:
/// - Prefixed with `custom+`
/// - Contains a literal `/`
/// - Contains zero or more digits
/// - Contains a literal `/`
/// - Contains at least one character that is not a control character and not the literal `$`
/// - Contains a literal `$`
/// - Contains at least one character that is not a control character and not the literal `$`
const VALID_INPUTS_CUSTOM_WITH_ORG: &str = r"custom\+/\d*/[^\pC$]+\$[^\pC$]+";
const VALID_INPUTS_CUSTOM_WITH_ORG: &str = r"custom\+\d*/[^\pC$]+\$[^\pC$]+";

proptest! {
/// Tests randomly generated strings that match the provided regular expression against the parser.
Expand Down
2 changes: 1 addition & 1 deletion src/locator_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ mod tests {
.expect("must parse locators");

let expected = vec![
"custom+baz",
"custom+1/bam",
"custom+2/bam",
"custom+baz",
"git+github.com/foo/bar",
"git+github.com/foo/bar",
];
Expand Down
9 changes: 8 additions & 1 deletion src/locator_strict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ mod tests {
assert_matches!(parsed, Err(Error::Parse(ParseError::Field { .. })));
}

#[test]
fn parse_empty_revision() {
let input = "git+project$";
let parsed = StrictLocator::parse(input);
assert_matches!(parsed, Err(Error::Parse(ParseError::Field { .. })));
}

#[test]
fn parse_invalid_syntax() {
let input = "";
Expand Down Expand Up @@ -385,9 +392,9 @@ mod tests {
.expect("must parse locators");

let expected = vec![
"custom+baz$1234",
"custom+1/bam$1234",
"custom+2/bam$1234",
"custom+baz$1234",
"git+github.com/foo/bar$abcd10",
"git+github.com/foo/bar$abcd11",
];
Expand Down

0 comments on commit 3ccfee0

Please sign in to comment.