Skip to content

Conversation

@ksew1
Copy link
Member

@ksew1 ksew1 commented Oct 23, 2025

Stack:

⚠️ Part of a stack created by spr. Do not merge manually using the UI - doing so may have unexpected results.

@ksew1 ksew1 requested a review from a team as a code owner October 23, 2025 10:54
@ksew1 ksew1 requested review from MKowalski8 and franciszekjob and removed request for a team October 23, 2025 10:54
commit-id:f673da00
@ksew1 ksew1 force-pushed the spr/master/a2fe82e0 branch from 85c48ae to bddfb28 Compare October 24, 2025 11:20
@ksew1 ksew1 force-pushed the spr/master/f673da00 branch from 60b47b3 to 154edfe Compare October 24, 2025 11:20
fn extract_versions(version_output: &str) -> Result<HashMap<String, Version>, VersionError> {
// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
static VERSION_REGEX: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"(?P<tool>\w+)[\s:]+(?P<ver>(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?)").expect("this should be a valid regex")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to mach unlimited number of whitespace between tool name and it's version, just an optional : and whitespace

Suggested change
Regex::new(r"(?P<tool>\w+)[\s:]+(?P<ver>(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?)").expect("this should be a valid regex")
Regex::new(r"(?P<tool>\w+):?\s(?P<ver>(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?)").expect("this should be a valid regex")

Also I think if you are already matching for digits, you don't need extra matches for numbers

Suggested change
Regex::new(r"(?P<tool>\w+)[\s:]+(?P<ver>(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?)").expect("this should be a valid regex")
Regex::new(r"(?P<tool>\w+)[\s:]+(?P<ver>(?:\d*)\.(?:\d*)\.(?:\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?)").expect("this should be a valid regex")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other groups could be simplified as well

Suggested change
Regex::new(r"(?P<tool>\w+)[\s:]+(?P<ver>(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?)").expect("this should be a valid regex")
Regex::new(r"(?P<tool>\w+):?\s(?P<ver>(?:\d*)\.(?:\d*)\.(?:\d*)(?:-(?:[0-9a-zA-Z-]+)(?:\.(?:[0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?)").expect("this should be a valid regex")

.collect()
}
#[cfg(test)]
mod tests {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add some more tests (even generate them through some LLM) for more versions combinations? As a sanity check for regexes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants