Skip to content

Commit f4421d8

Browse files
committed
fix: don't mistake prefixed tags for versions (#262)
Previously we would be too generious when accepting version tags, now we accept the prefixes 'v' and 'vers' and no prefix at all.
1 parent 4a948d0 commit f4421d8

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

cargo-smart-release/src/utils.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,13 @@ pub fn parse_possibly_prefixed_tag_version(package_name: Option<&str>, tag_name:
127127
}
128128

129129
pub fn parse_tag_version(name: &BStr) -> Option<Version> {
130-
name.find_byteset(b"0123456789")
131-
.and_then(|pos| name[pos..].to_str().ok())
132-
.and_then(|v| Version::parse(v).ok())
130+
let version = name
131+
.strip_prefix(b"vers")
132+
.or_else(|| name.strip_prefix(b"v"))
133+
.unwrap_or_else(|| name.as_bytes())
134+
.to_str()
135+
.ok()?;
136+
Version::parse(version).ok()
133137
}
134138

135139
pub fn is_tag_name(package_name: &str, tag_name: &git::bstr::BStr) -> bool {
@@ -259,13 +263,22 @@ mod tests {
259263
fn funky() {
260264
assert!(!is_tag_version(b"vHi.Ho.yada-anythingreally".as_bstr()));
261265
}
266+
267+
#[test]
268+
fn prefixed() {
269+
assert!(!is_tag_version(b"cargo-v1.0.0".as_bstr()));
270+
}
262271
}
263272
mod matches {
264273
use git_repository::bstr::ByteSlice;
265274

275+
#[test]
276+
fn no_prefix() {
277+
assert!(is_tag_version(b"0.0.1".as_bstr()));
278+
}
279+
266280
#[test]
267281
fn custom_prefix() {
268-
assert!(is_tag_version(b"x0.0.1".as_bstr()));
269282
assert!(is_tag_version(b"vers0.0.1".as_bstr()));
270283
}
271284

0 commit comments

Comments
 (0)