Skip to content

Commit fe12533

Browse files
committed
Made Version.SortableString() comparable directly with RelaxedVersion.SortableString()
1 parent aa0ac68 commit fe12533

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,22 @@ This is accomplished by adding some adjustment characters to the original semver
113113

114114
To give you an idea on how it works, the following table shows some examples of semver versions and their `SortableString` counter part:
115115

116-
| semver | `SortableString()` |
117-
| ------------------ | ------------------ |
118-
| `1.2.4` | `1.2.4;` |
119-
| `1.3.0-rc` | `1.3.0-;rc` |
120-
| `1.3.0-rc.0` | `1.3.0-;rc,:0` |
121-
| `1.3.0-rc.5` | `1.3.0-;rc,:5` |
122-
| `1.3.0-rc.5+build` | `1.3.0-;rc,:5` |
123-
| `1.3.0-rc.20` | `1.3.0-;rc,::20` |
124-
| `1.3.0-rc-` | `1.3.0-;rc-` |
125-
| `1.3.0` | `1.3.0;` |
126-
| `1.20.0` | `1.:20.0;` |
127-
| `1.90.0` | `1.:90.0;` |
128-
| `1.300.0-6` | `1.::300.0-:6` |
129-
| `1.300.0-30` | `1.::300.0-::30` |
130-
| `1.300.0-1pre` | `1.::300.0-;1pre` |
131-
| `1.300.0-pre` | `1.::300.0-;pre` |
132-
| `1.300.0` | `1.::300.0;` |
116+
| semver | `SortableString()` |
117+
| ------------------ | ------------------- |
118+
| `1.2.4` | `;1.2.4;` |
119+
| `1.3.0-rc` | `;1.3.0-;rc` |
120+
| `1.3.0-rc.0` | `;1.3.0-;rc,:0` |
121+
| `1.3.0-rc.5` | `;1.3.0-;rc,:5` |
122+
| `1.3.0-rc.5+build` | `;1.3.0-;rc,:5` |
123+
| `1.3.0-rc.20` | `;1.3.0-;rc,::20` |
124+
| `1.3.0-rc-` | `;1.3.0-;rc-` |
125+
| `1.3.0` | `;1.3.0;` |
126+
| `1.20.0` | `;1.:20.0;` |
127+
| `1.90.0` | `;1.:90.0;` |
128+
| `1.300.0-6` | `;1.::300.0-:6` |
129+
| `1.300.0-30` | `;1.::300.0-::30` |
130+
| `1.300.0-1pre` | `;1.::300.0-;1pre` |
131+
| `1.300.0-pre` | `;1.::300.0-;pre` |
132+
| `1.300.0` | `;1.::300.0;` |
133133

134134
The `SortableString()` can be used in SQL databases to simplify the ordering of a set of versions in a table.

relaxed_version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (v *RelaxedVersion) CompatibleWith(u *RelaxedVersion) bool {
114114
// introduced in a system that doesn't support semver ordering.
115115
func (v *RelaxedVersion) SortableString() string {
116116
if v.version != nil {
117-
return ";" + v.version.SortableString()
117+
return v.version.SortableString()
118118
}
119119
return ":" + string(v.customversion)
120120
}

version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ func (v *Version) SortableString() string {
455455
vPatch = v.bytes[v.minor+1 : v.patch]
456456
}
457457

458-
res := encodeNumber(vMajor) + "." + encodeNumber(vMinor) + "." + encodeNumber(vPatch)
458+
res := ";" + encodeNumber(vMajor) + "." + encodeNumber(vMinor) + "." + encodeNumber(vPatch)
459459
// If there is no pre-release, add a ";" to the end, otherwise add a "-" followed by the pre-release.
460460
// This ensure the correct ordering of the pre-release versions (that are always lower than the normal versions).
461461
if v.prerelease == v.patch {

0 commit comments

Comments
 (0)