1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

fix(aur): description with quotes (#5304)

Currently, the field `pkgdesc` is wrapped by simple quotes, but if the
description also contains simple quotes it breaks the package.

So it's not possible to publish a package that contains "Let's Encrypt"
inside the description.

This PR wraps the description with the right quotes depending on the
description content.

If there is a mix of quotes, it replaces, arbitrarily, double quotes
with single quotes.

Example with double quotes inside the description:
https://gitlab.archlinux.org/archlinux/packaging/packages/cargo-release/-/blob/main/PKGBUILD?ref_type=heads

Example with simple quotes inside the description:
https://gitlab.archlinux.org/archlinux/packaging/packages/cargo-modules/-/blob/main/PKGBUILD?ref_type=heads
This commit is contained in:
Ludovic Fernandez 2024-11-22 13:56:52 +01:00 committed by GitHub
parent 50d51ac898
commit 377981ebd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 123 additions and 3 deletions

View File

@ -218,12 +218,27 @@ func fixLines(s string) string {
return strings.Join(result, "\n")
}
func quoteField(v string) string {
simpleQuote := strings.Contains(v, `'`)
doubleQuote := strings.Contains(v, `"`)
switch {
case simpleQuote && doubleQuote:
return `"` + strings.ReplaceAll(v, `"`, `'`) + `"`
case simpleQuote:
return `"` + v + `"`
default:
return `'` + v + `'`
}
}
func applyTemplate(ctx *context.Context, tpl string, data templateData) (string, error) {
t := template.Must(
template.New(data.Name).
Funcs(template.FuncMap{
"fixLines": fixLines,
"pkgArray": toPkgBuildArray,
"fixLines": fixLines,
"pkgArray": toPkgBuildArray,
"quoteField": quoteField,
}).
Parse(tpl),
)

View File

@ -249,6 +249,21 @@ func TestFullPipe(t *testing.T) {
},
expectedPublishErrorCheck: testlib.RequireTemplateError,
},
"simple-quote-inside-description": {
prepare: func(ctx *context.Context) {
ctx.Config.AURs[0].Description = "Let's go"
},
},
"double-quote-inside-description": {
prepare: func(ctx *context.Context) {
ctx.Config.AURs[0].Description = `This is a "test"`
},
},
"mixed-quote-inside-description": {
prepare: func(ctx *context.Context) {
ctx.Config.AURs[0].Description = `Let's go, this is a "test"`
},
},
} {
t.Run(name, func(t *testing.T) {
url := testlib.GitMakeBareRepository(t)

View File

@ -0,0 +1,18 @@
# This file was generated by GoReleaser. DO NOT EDIT.
pkgname='double-quote-inside-description-bin'
pkgver=1.0.1
pkgrel=1
pkgdesc='This is a "test"'
url=''
arch=('x86_64')
license=('MIT')
provides=('double-quote-inside-description')
conflicts=('double-quote-inside-description')
source_x86_64=("${pkgname}_${pkgver}_x86_64.tar.gz::https://dummyhost/download/v1.0.1-foo/bin.tar.gz")
sha256sums_x86_64=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
package() {
install -Dm755 "./name" "${pkgdir}/usr/bin/name"
}

View File

@ -0,0 +1,12 @@
pkgbase = double-quote-inside-description-bin
pkgdesc = This is a "test"
pkgver = 1.0.1
pkgrel = 1
license = MIT
conflicts = double-quote-inside-description
provides = double-quote-inside-description
arch = x86_64
source_x86_64 = https://dummyhost/download/v1.0.1-foo/bin.tar.gz
sha256sums_x86_64 = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
pkgname = double-quote-inside-description-bin

View File

@ -0,0 +1,18 @@
# This file was generated by GoReleaser. DO NOT EDIT.
pkgname='mixed-quote-inside-description-bin'
pkgver=1.0.1
pkgrel=1
pkgdesc="Let's go, this is a 'test'"
url=''
arch=('x86_64')
license=('MIT')
provides=('mixed-quote-inside-description')
conflicts=('mixed-quote-inside-description')
source_x86_64=("${pkgname}_${pkgver}_x86_64.tar.gz::https://dummyhost/download/v1.0.1-foo/bin.tar.gz")
sha256sums_x86_64=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
package() {
install -Dm755 "./name" "${pkgdir}/usr/bin/name"
}

View File

@ -0,0 +1,12 @@
pkgbase = mixed-quote-inside-description-bin
pkgdesc = Let's go, this is a "test"
pkgver = 1.0.1
pkgrel = 1
license = MIT
conflicts = mixed-quote-inside-description
provides = mixed-quote-inside-description
arch = x86_64
source_x86_64 = https://dummyhost/download/v1.0.1-foo/bin.tar.gz
sha256sums_x86_64 = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
pkgname = mixed-quote-inside-description-bin

View File

@ -0,0 +1,18 @@
# This file was generated by GoReleaser. DO NOT EDIT.
pkgname='simple-quote-inside-description-bin'
pkgver=1.0.1
pkgrel=1
pkgdesc="Let's go"
url=''
arch=('x86_64')
license=('MIT')
provides=('simple-quote-inside-description')
conflicts=('simple-quote-inside-description')
source_x86_64=("${pkgname}_${pkgver}_x86_64.tar.gz::https://dummyhost/download/v1.0.1-foo/bin.tar.gz")
sha256sums_x86_64=('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
package() {
install -Dm755 "./name" "${pkgdir}/usr/bin/name"
}

View File

@ -0,0 +1,12 @@
pkgbase = simple-quote-inside-description-bin
pkgdesc = Let's go
pkgver = 1.0.1
pkgrel = 1
license = MIT
conflicts = simple-quote-inside-description
provides = simple-quote-inside-description
arch = x86_64
source_x86_64 = https://dummyhost/download/v1.0.1-foo/bin.tar.gz
sha256sums_x86_64 = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
pkgname = simple-quote-inside-description-bin

View File

@ -38,7 +38,7 @@ const aurTemplateData = `# This file was generated by GoReleaser. DO NOT EDIT.
pkgname='{{ .Name }}'
pkgver={{ .Version }}
pkgrel={{ .Rel }}
pkgdesc='{{ .Desc }}'
pkgdesc={{ quoteField .Desc }}
url='{{ .Homepage }}'
arch=({{ pkgArray .Arches }})
license=('{{ .License }}')