Skip to content

Commit

Permalink
[Fix] Fixed regression introduced in v0.30.0 causing `ValueError: Inv…
Browse files Browse the repository at this point in the history
…alid semantic version: 0.33.1+420240816190912` (#729)

## Changes

This PR fixes SemVer regex to follow the official recommendation to
capture more patterns. It also ensures that patterns are both SemVer and
PEP440 compliant.

## Tests

- [x] `make test` run locally
- [x] `make fmt` applied
- [ ] relevant integration tests applied
  • Loading branch information
nfx authored Aug 19, 2024
1 parent c3d1db5 commit 19fe05c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion databricks/sdk/useragent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@

# Precompiled regex patterns
alphanum_pattern = re.compile(r'^[a-zA-Z0-9_.+-]+$')
semver_pattern = re.compile(r'^v?(\d+\.)?(\d+\.)?(\*|\d+)$')

# official https://semver.org/ recommendation: https://regex101.com/r/Ly7O1x/
# with addition of "x" wildcards for minor/patch versions. Also, patch version may be omitted.
semver_pattern = re.compile(r"^"
r"(?P<major>0|[1-9]\d*)\.(?P<minor>x|0|[1-9]\d*)(\.(?P<patch>x|0|[1-9x]\d*))?"
r"(?:-(?P<pre_release>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)"
r"(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?"
r"(?:\+(?P<build>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$")


def _match_alphanum(value):
Expand Down

0 comments on commit 19fe05c

Please sign in to comment.