Skip to content

Commit fe27a62

Browse files
committed
refactor: simplify version regex handling in create distrobox helpers
1 parent e8f54a2 commit fe27a62

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

src/dialogs/create_distrobox_helpers.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ use regex::Regex;
55

66
// Matches tags that are numeric-only (e.g. "1.2.3" or "1_2-3")
77
static VERSION_RE: LazyLock<Regex> =
8-
LazyLock::new(|| Regex::new(r"^(?:\d+(?:[._-]\d+)*)$").unwrap());
9-
// Capture a numeric version inside a tag (e.g. "v1.2" -> captures "1.2")
10-
static VER_CAPTURE_RE: LazyLock<Regex> =
11-
LazyLock::new(|| Regex::new(r"(?P<ver>\d+(?:[._-]\d+)*)").unwrap());
8+
LazyLock::new(|| Regex::new(r"^(?P<ver>\d+(?:[._-]\d+)*)$").unwrap());
129

1310
// Compare two numeric-version vectors treating missing components as zeros.
1411
fn compare_version_vec(a: &[u64], b: &[u64]) -> std::cmp::Ordering {
@@ -176,17 +173,15 @@ pub fn derive_image_prefill(
176173
if tag_l == "edge" {
177174
continue;
178175
}
179-
// require the whole tag to be numeric-like, then capture the numeric portion
180-
if VERSION_RE.is_match(&tag_l) {
181-
if let Some(cap) = VER_CAPTURE_RE.captures(&tag_l) {
182-
let ver = &cap["ver"];
183-
let nums: Vec<u64> = ver
184-
.split(|c| c == '.' || c == '_' || c == '-')
185-
.filter_map(|p| p.parse::<u64>().ok())
186-
.collect();
187-
if !nums.is_empty() {
188-
semvers.push(((*img), nums));
189-
}
176+
// require the whole tag to be numeric-like
177+
if let Some(cap) = VERSION_RE.captures(&tag_l) {
178+
let ver = &cap["ver"];
179+
let nums: Vec<u64> = ver
180+
.split(|c| c == '.' || c == '_' || c == '-')
181+
.filter_map(|p| p.parse::<u64>().ok())
182+
.collect();
183+
if !nums.is_empty() {
184+
semvers.push(((*img), nums));
190185
}
191186
}
192187
}

0 commit comments

Comments
 (0)