Skip to content

Commit

Permalink
Don't interpret version numbers as regular expressions.
Browse files Browse the repository at this point in the history
Don't interpret version numbers as regular expressions in source parameters for versions that allow regular expressions.

Fixes #8739.
  • Loading branch information
fniessink committed Aug 27, 2024
1 parent 52376d4 commit 0e9ac58
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
19 changes: 18 additions & 1 deletion components/collector/src/collector_utilities/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,24 @@ def sha1_hash(string: str) -> str:

def is_regexp(string: str) -> bool:
"""Return whether the string looks like a regular expression."""
return bool(set("$^?.+*[]") & set(string))
return False if matches_semantic_version(string) else bool(set("$^?.+*[]") & set(string))


def matches_semantic_version(string) -> bool:
"""Return whether the string is a semantic version number.
Regular expression taken from
https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string.
"""
return (
re.match(
r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)"
r"(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?"
r"(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$",
string,
)
is not None
)


def match_string_or_regular_expression(string: str, strings_and_or_regular_expressions: Collection[str]) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def test_is_regexp(self):
self.assertTrue(is_regexp("bar?foo"))
self.assertTrue(is_regexp("[a-z]+foo"))

def test_semantic_version_are_no_regexp(self):
"""Test that semantic version numbers are not considered a regular expression."""
self.assertFalse(is_regexp("1.2.3"))
self.assertFalse(is_regexp("1.2.3-rc.0"))
self.assertTrue(is_regexp("v10.2"))
self.assertTrue(is_regexp("foo 10.2"))


class IterableToBatchesTest(unittest.TestCase):
"""Unit tests for the iterable_to_batches function."""
Expand Down
4 changes: 4 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

If your currently installed *Quality-time* version is not v5.15.0, please first check the upgrade path in the [versioning policy](versioning.md).

### Fixed

- Don't interpret version number parameters as regular expressions. Fixes [#8739](https://github.com/ICTU/quality-time/issues/8739).

### Added

- Allow for configuring Jenkins as source for the metric 'CI-pipeline duration' (GitLab CI was already supported, Azure DevOps will follow later). Partially implements [#6423](https://github.com/ICTU/quality-time/issues/6423).
Expand Down

0 comments on commit 0e9ac58

Please sign in to comment.