diff --git a/rpm/rpm.go b/rpm/rpm.go index 5ec04d14..3e98b709 100644 --- a/rpm/rpm.go +++ b/rpm/rpm.go @@ -271,7 +271,7 @@ func formatVersion(info *nfpm.Info) string { version := info.Version if info.Prerelease != "" { - version += "~" + info.Prerelease + version += "~" + strings.ReplaceAll(info.Prerelease, "-", "_") } if info.VersionMetadata != "" { diff --git a/rpm/rpm_test.go b/rpm/rpm_test.go index 62ab016e..7569871f 100644 --- a/rpm/rpm_test.go +++ b/rpm/rpm_test.go @@ -420,6 +420,16 @@ func TestRPMVersionWithPrerelease(t *testing.T) { require.Equal(t, "1", meta.Release) } +func TestRPMVersionWithPrereleaseWithDashes(t *testing.T) { + info := exampleInfo() + info.Version = "1.0.0" + info.Prerelease = "rc1-alpha-omega" // nolint:goconst + meta, err := buildRPMMeta(info) + require.NoError(t, err) + require.Equal(t, "1.0.0~rc1_alpha_omega", meta.Version) + require.Equal(t, "1", meta.Release) +} + func TestRPMVersionWithReleaseAndPrerelease(t *testing.T) { // https://fedoraproject.org/wiki/Package_Versioning_Examples#Complex_versioning_examples info := exampleInfo()