mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-10 17:32:15 +01:00
fixes #104
This commit is contained in:
1
go.mod
1
go.mod
@@ -19,4 +19,5 @@ require (
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect
|
||||
golang.org/x/text v0.3.2
|
||||
)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/thecodingmachine/gotenberg/internal/app/xhttp/pkg/resource"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/conf"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/normalize"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/pm2"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
||||
@@ -110,7 +111,11 @@ func (ctx *Context) WithResource(directoryName string) error {
|
||||
return r, err
|
||||
}
|
||||
defer in.Close() // nolint: errcheck
|
||||
if err := r.WithFile(fh.Filename, in); err != nil {
|
||||
filename, err := normalize.String(fh.Filename)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
if err := r.WithFile(filename, in); err != nil {
|
||||
return r, err
|
||||
}
|
||||
}
|
||||
|
||||
9
internal/pkg/normalize/doc.go
Normal file
9
internal/pkg/normalize/doc.go
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
Package normalize helps removing special
|
||||
characters from a string.
|
||||
|
||||
Fixes: https://github.com/thecodingmachine/gotenberg/issues/104
|
||||
|
||||
Credits: https://medium.com/@swdream/golang-remove-all-accents-in-string-319abf6a7f5b
|
||||
*/
|
||||
package normalize
|
||||
21
internal/pkg/normalize/normalize.go
Normal file
21
internal/pkg/normalize/normalize.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package normalize
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
||||
"golang.org/x/text/runes"
|
||||
"golang.org/x/text/transform"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
)
|
||||
|
||||
// String normalizes given string.
|
||||
func String(str string) (string, error) {
|
||||
const op string = "normalize.String"
|
||||
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
|
||||
result, _, err := transform.String(t, str)
|
||||
if err != nil {
|
||||
return "", xerror.New(op, err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
17
internal/pkg/normalize/normalize_test.go
Normal file
17
internal/pkg/normalize/normalize_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package normalize
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
const (
|
||||
toNormalize string = "analise da aplicação"
|
||||
expected string = "analise da aplicacao"
|
||||
)
|
||||
v, err := String(toNormalize)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expected, v)
|
||||
}
|
||||
Reference in New Issue
Block a user