Skip to content

Commit

Permalink
fix: berry lockfile semver range parsing of valid floats (#4945)
Browse files Browse the repository at this point in the history
### Description

I believe this is probably the culprit behind #4925. 

`serde_yaml` parses `1` as an unsigned int, `1.2` as a float, and
`1.2.3` as a string. We were missing handling the float case.

### Testing Instructions

Added unit test of deserialization of semver ranges that's a valid float
  • Loading branch information
chris-olszewski committed May 16, 2023
1 parent 03de43d commit 617a1fa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/turborepo-lockfiles/src/berry/de.rs
Expand Up @@ -27,12 +27,14 @@ impl<'de> Deserialize<'de> for SemverString {
#[serde(untagged)]
enum StringOrNum {
String(String),
Num(u64),
Int(u64),
Float(f32),
}

match StringOrNum::deserialize(deserializer)? {
StringOrNum::String(s) => Ok(SemverString(s)),
StringOrNum::Num(x) => Ok(SemverString(x.to_string())),
StringOrNum::Int(x) => Ok(SemverString(x.to_string())),
StringOrNum::Float(f) => Ok(SemverString(f.to_string())),
}
}
}
Expand All @@ -48,12 +50,14 @@ mod test {
let input = "foo: 1.2.3
bar: 2
baz: latest
oop: 1.3
";

let result: HashMap<String, SemverString> = serde_yaml::from_str(input).unwrap();

assert_eq!(result["foo"].as_ref(), "1.2.3");
assert_eq!(result["bar"].as_ref(), "2");
assert_eq!(result["baz"].as_ref(), "latest");
assert_eq!(result["oop"].as_ref(), "1.3")
}
}

0 comments on commit 617a1fa

Please sign in to comment.