Skip to content

Commit

Permalink
Ensure that string(::VersionSpec) is compatible with semver_spec()
Browse files Browse the repository at this point in the history
It is an unfortunate coincidence that if you try to print out a
`VersionSpec` to a project's `compat` field, it can be in a format that
`semver_spec()` rejects due to the ambiguity of `1.2.0-1.4.0` being
either a prerelease with a very strange prerelease tag, or a range of
versions.  We reduce the ambiguity by changing `VersionSpec` to always
print its bounds with a separating space.
  • Loading branch information
staticfloat committed Aug 11, 2023
1 parent 78d809b commit 9a91b11
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Versions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ function Base.print(io::IO, r::VersionRange)
if (m, n) == (0, 0)
print(io, '*')
elseif m == 0
print(io, "0-")
print(io, "0 -")
join(io, r.upper.t, '.')
elseif n == 0
join(io, r.lower.t, '.')
print(io, "-*")
else
join(io, r.lower.t[1:m], '.')
if r.lower != r.upper
print(io, '-')
print(io, " - ")
join(io, r.upper.t[1:n], '.')
end
end
Expand Down
1 change: 1 addition & 0 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ import Pkg.Types: semver_spec, VersionSpec
@test !(v"0.3" in semver_spec("0.1 - 0.2"))
@test v"0.2.99" in semver_spec("0.1 - 0.2")
@test v"0.3" in semver_spec("0.1 - 0")
@test semver_spec(string(VersionSpec("1-2"))) == VersionSpec("1-2")

@test_throws ErrorException semver_spec("^^0.2.3")
@test_throws ErrorException semver_spec("^^0.2.3.4")
Expand Down

0 comments on commit 9a91b11

Please sign in to comment.