diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 472366db..008c2b52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: rust: [nightly, beta, stable, 1.52.0, 1.46.0, 1.40.0, 1.39.0, 1.36.0, 1.33.0, 1.32.0, 1.31.0] timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{matrix.rust}} @@ -46,7 +46,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - run: npm install semver - run: cargo test @@ -60,7 +60,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly - run: cargo generate-lockfile -Z minimal-versions - run: cargo check --locked --features serde @@ -71,7 +71,7 @@ jobs: if: github.event_name != 'pull_request' timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@clippy - run: cargo clippy --tests --benches -- -Dclippy::all -Dclippy::pedantic @@ -84,7 +84,7 @@ jobs: MIRIFLAGS: -Zmiri-strict-provenance timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@miri - name: Run cargo miri test (64-bit little endian) run: cargo miri test --target x86_64-unknown-linux-gnu @@ -102,7 +102,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly - uses: dtolnay/install@cargo-fuzz - run: cargo fuzz check @@ -113,7 +113,7 @@ jobs: if: github.event_name != 'pull_request' timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/install@cargo-outdated - run: cargo outdated --workspace --exit-code 1 - run: cargo outdated --manifest-path fuzz/Cargo.toml --exit-code 1 diff --git a/Cargo.toml b/Cargo.toml index 863f7386..f40e9521 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "semver" -version = "1.0.18" +version = "1.0.19" authors = ["David Tolnay "] categories = ["data-structures", "no-std"] description = "Parser and evaluator for Cargo's flavor of Semantic Versioning" diff --git a/src/impls.rs b/src/impls.rs index c3b6c601..cc4fd415 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -38,13 +38,13 @@ impl Deref for BuildMetadata { impl PartialOrd for Prerelease { fn partial_cmp(&self, rhs: &Self) -> Option { - Some(Ord::cmp(self, rhs)) + Some(self.cmp(rhs)) } } impl PartialOrd for BuildMetadata { fn partial_cmp(&self, rhs: &Self) -> Option { - Some(Ord::cmp(self, rhs)) + Some(self.cmp(rhs)) } } diff --git a/src/lib.rs b/src/lib.rs index d2c4eb37..88f24383 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,7 +60,7 @@ //! //! [Specifying Dependencies]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html -#![doc(html_root_url = "https://docs.rs/semver/1.0.18")] +#![doc(html_root_url = "https://docs.rs/semver/1.0.19")] #![cfg_attr(doc_cfg, feature(doc_cfg))] #![cfg_attr(all(not(feature = "std"), not(no_alloc_crate)), no_std)] #![cfg_attr(not(no_unsafe_op_in_unsafe_fn_lint), deny(unsafe_op_in_unsafe_fn))] diff --git a/tests/test_identifier.rs b/tests/test_identifier.rs index dc888c9c..40d85965 100644 --- a/tests/test_identifier.rs +++ b/tests/test_identifier.rs @@ -43,3 +43,9 @@ fn test_eq() { assert_ne!(prerelease("aaaaaaaaa"), prerelease("bbbbbbbbb")); assert_ne!(build_metadata("1"), build_metadata("001")); } + +#[test] +fn test_prerelease() { + let err = prerelease_err("1.b\0"); + assert_to_string(err, "unexpected character in pre-release identifier"); +} diff --git a/tests/test_version.rs b/tests/test_version.rs index de3628fa..991087f7 100644 --- a/tests/test_version.rs +++ b/tests/test_version.rs @@ -47,6 +47,18 @@ fn test_parse() { let err = version_err("1.2.3-01"); assert_to_string(err, "invalid leading zero in pre-release identifier"); + let err = version_err("1.2.3++"); + assert_to_string(err, "empty identifier segment in build metadata"); + + let err = version_err("07"); + assert_to_string(err, "invalid leading zero in major version number"); + + let err = version_err("111111111111111111111.0.0"); + assert_to_string(err, "value of major version number exceeds u64::MAX"); + + let err = version_err("8\0"); + assert_to_string(err, "unexpected character '\\0' after major version number"); + let parsed = version("1.2.3"); let expected = Version::new(1, 2, 3); assert_eq!(parsed, expected); diff --git a/tests/test_version_req.rs b/tests/test_version_req.rs index 98a03ac8..1ed2358a 100644 --- a/tests/test_version_req.rs +++ b/tests/test_version_req.rs @@ -168,6 +168,9 @@ pub fn test_multiple() { // https://github.com/steveklabnik/semver/issues/56 let err = req_err("1.2.3 - 2.3.4"); assert_to_string(err, "expected comma after patch version number, found '-'"); + + let err = req_err(">1, >2, >3, >4, >5, >6, >7, >8, >9, >10, >11, >12, >13, >14, >15, >16, >17, >18, >19, >20, >21, >22, >23, >24, >25, >26, >27, >28, >29, >30, >31, >32, >33"); + assert_to_string(err, "excessive number of version comparators"); } #[test] @@ -332,7 +335,7 @@ pub fn test_pre() { } #[test] -pub fn test_parse_errors() { +pub fn test_parse() { let err = req_err("\0"); assert_to_string( err, @@ -367,6 +370,45 @@ pub fn test_parse_errors() { ); } +#[test] +fn test_comparator_parse() { + let parsed = comparator("1.2.3-alpha"); + assert_to_string(parsed, "^1.2.3-alpha"); + + let parsed = comparator("2.X"); + assert_to_string(parsed, "2.*"); + + let parsed = comparator("2"); + assert_to_string(parsed, "^2"); + + let parsed = comparator("2.x.x"); + assert_to_string(parsed, "2.*"); + + let err = comparator_err("1.2.3-01"); + assert_to_string(err, "invalid leading zero in pre-release identifier"); + + let err = comparator_err("1.2.3+4."); + assert_to_string(err, "empty identifier segment in build metadata"); + + let err = comparator_err(">"); + assert_to_string( + err, + "unexpected end of input while parsing major version number", + ); + + let err = comparator_err("1."); + assert_to_string( + err, + "unexpected end of input while parsing minor version number", + ); + + let err = comparator_err("1.*."); + assert_to_string(err, "unexpected character after wildcard in version req"); + + let err = comparator_err("1.2.3+4ÿ"); + assert_to_string(err, "unexpected character 'ÿ' after build metadata"); +} + #[test] fn test_cargo3202() { let ref r = req("0.*.*"); diff --git a/tests/util/mod.rs b/tests/util/mod.rs index 5cc142c4..07d691fa 100644 --- a/tests/util/mod.rs +++ b/tests/util/mod.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -use semver::{BuildMetadata, Error, Prerelease, Version, VersionReq}; +use semver::{BuildMetadata, Comparator, Error, Prerelease, Version, VersionReq}; use std::fmt::Display; #[cfg_attr(not(no_track_caller), track_caller)] @@ -23,11 +23,26 @@ pub(super) fn req_err(text: &str) -> Error { VersionReq::parse(text).unwrap_err() } +#[cfg_attr(not(no_track_caller), track_caller)] +pub(super) fn comparator(text: &str) -> Comparator { + Comparator::parse(text).unwrap() +} + +#[cfg_attr(not(no_track_caller), track_caller)] +pub(super) fn comparator_err(text: &str) -> Error { + Comparator::parse(text).unwrap_err() +} + #[cfg_attr(not(no_track_caller), track_caller)] pub(super) fn prerelease(text: &str) -> Prerelease { Prerelease::new(text).unwrap() } +#[cfg_attr(not(no_track_caller), track_caller)] +pub(super) fn prerelease_err(text: &str) -> Error { + Prerelease::new(text).unwrap_err() +} + #[cfg_attr(not(no_track_caller), track_caller)] pub(super) fn build_metadata(text: &str) -> BuildMetadata { BuildMetadata::new(text).unwrap()