Skip to content

Conversation

@ksew1
Copy link
Member

@ksew1 ksew1 commented Oct 23, 2025

No description provided.

@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
@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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

@ksew1 ksew1 force-pushed the spr/master/a2fe82e0 branch from bddfb28 to b5c96e0 Compare October 26, 2025 17:12
@ksew1 ksew1 force-pushed the spr/master/f673da00 branch 3 times, most recently from b91a450 to d62c883 Compare October 26, 2025 20:03
@ksew1 ksew1 requested a review from cptartur October 26, 2025 20:31
github-merge-queue bot pushed a commit that referenced this pull request Oct 28, 2025
commit-id:e0444c34

---

**Stack**:
- #3861
- #3860
- #3859⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do
not merge manually using the UI - doing so may have unexpected results.*
@ksew1 ksew1 force-pushed the spr/master/f673da00 branch from d62c883 to c7226bc Compare October 28, 2025 17:57
@ksew1 ksew1 force-pushed the spr/master/a2fe82e0 branch from b5c96e0 to 0e868b9 Compare October 28, 2025 17:57
github-merge-queue bot pushed a commit that referenced this pull request Oct 28, 2025
commit-id:a2fe82e0

---

**Stack**:
- #3861
- #3860⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do
not merge manually using the UI - doing so may have unexpected results.*
Base automatically changed from spr/master/a2fe82e0 to master October 28, 2025 18:46
commit-id:f673da00
@ksew1 ksew1 force-pushed the spr/master/f673da00 branch from c7226bc to 836a1e8 Compare October 28, 2025 18:50
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.

3 participants