Skip to content

Commit 21f5caf

Browse files
committed
Return latest version if requested version is any
I believe this is a bug in semver crate but according to NPM people, and @steveklabnik; a version like "0.1.0-pre.0" or "0.1.0-beta.0" *is not a real version* and any version that contains a pre-release string is getting different treatment by semver. IMO this is utterly wrong. Docs.rs is probably the first victim of this behavior and it will affect more in future. `*` means any and it should match any version. It doesn't matter if a version have a pre-release string or not. Even older versions of node's semver were matching "*" for any version. I don't know why they changed this behavior but I am not surprised any means "anything except a version that contains pre-release" in JS world. Fixes: rust-lang#80 Ref: dtolnay/semver#98
1 parent 7fd30e6 commit 21f5caf

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/web/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ fn match_version(conn: &Connection, name: &str, version: Option<&str>) -> Option
231231
versions_sem
232232
};
233233

234+
// semver is acting weird for '*' (any) range if a crate only have pre-release versions
235+
// return first version if requested version is '*'
236+
if req_version == "*" && !versions_sem.is_empty() {
237+
return Some(format!("{}", versions_sem[0]));
238+
}
239+
234240
for version in &versions_sem {
235241
if req_sem_ver.matches(&version) {
236242
return Some(format!("{}", version))

0 commit comments

Comments
 (0)