Skip to content

Commit

Permalink
Fix #2901: VersionRange.toString() doesn't handle >0.0.0
Browse files Browse the repository at this point in the history
The `VersionRange.toString` method was not ideal and dropping
this rare case. A tiny improvement that was also done in the
process is to give higher priority to `matchesAny` so that
we get a more user-friendly output, given how common it is
(e.g. for `ToolchainRequirement`).
  • Loading branch information
Geod24 committed Jun 11, 2024
1 parent a913071 commit 290e3ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions source/dub/dependency.d
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ public struct VersionRange
string r;

if (this == Invalid) return "no";
if (this.matchesAny()) return "*";
if (this.isExactVersion() && m_inclusiveA && m_inclusiveB) {
// Special "==" case
if (m_versA == Version.masterBranch) return "~master";
Expand All @@ -1142,9 +1143,12 @@ public struct VersionRange
}
}

if (m_versA != Version.minRelease) r = (m_inclusiveA ? ">=" : ">") ~ m_versA.toString();
if (m_versB != Version.maxRelease) r ~= (r.length==0 ? "" : " ") ~ (m_inclusiveB ? "<=" : "<") ~ m_versB.toString();
if (this.matchesAny()) r = ">=0.0.0";
if (m_versA != Version.minRelease || !m_inclusiveA)
r = (m_inclusiveA ? ">=" : ">") ~ m_versA.toString();
if (m_versB != Version.maxRelease || !m_inclusiveB)
r ~= (r.length == 0 ? "" : " ") ~ (m_inclusiveB ? "<=" : "<") ~
m_versB.toString();

return r;
}

Expand Down Expand Up @@ -1241,6 +1245,13 @@ unittest {
assert(Version("1.0.0+foo").matches(Version("1.0.0+foo"), VersionMatchMode.strict));
}

// Erased version specification for dependency, converted to "" instead of ">0.0.0"
// https://github.com/dlang/dub/issues/2901
unittest
{
assert(VersionRange.fromString(">0.0.0").toString() == ">0.0.0");
}

/// Determines whether the given string is a Git hash.
bool isGitHash(string hash) @nogc nothrow pure @safe
{
Expand Down
2 changes: 1 addition & 1 deletion test/5-convert/dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ copyright "Copyright © 2015, nobody"
license "BSD 2-clause"
x:ddoxFilterArgs "dfa1" "dfa2"
x:ddoxTool "ddoxtool"
dependency "describe-dependency-1:sub1" version=">=0.0.0"
dependency "describe-dependency-1:sub1" version="*"
targetType "sourceLibrary"
subConfiguration "describe-dependency-1:sub1" "library"
dflags "--another-dflag"
Expand Down

0 comments on commit 290e3ce

Please sign in to comment.