Two base64 fixes

master
Jan-Lukas Else 6 days ago
parent e8a5e9eb0e
commit 8c86c21d77

@ -4,9 +4,7 @@ import (
"context"
"encoding/base64"
"net/http"
"net/url"
"path"
"strings"
)
const defaultSearchPath = "/search"
@ -38,16 +36,11 @@ func (a *goBlog) serveSearchResult(w http.ResponseWriter, r *http.Request) {
}
func searchEncode(search string) string {
return url.PathEscape(strings.ReplaceAll(base64.StdEncoding.EncodeToString([]byte(search)), "/", "_"))
return base64.URLEncoding.EncodeToString([]byte(search))
}
func searchDecode(encoded string) string {
encoded, err := url.PathUnescape(encoded)
if err != nil {
return ""
}
encoded = strings.ReplaceAll(encoded, "_", "/")
db, err := base64.StdEncoding.DecodeString(encoded)
db, err := base64.URLEncoding.DecodeString(encoded)
if err != nil {
return ""
}

@ -221,12 +221,8 @@ func (a *goBlog) createTTSAudio(lang, ssml string, w io.Writer) error {
// Decode response
if encoded, ok := response["audioContent"]; ok {
if encodedStr, ok := encoded.(string); ok {
if audio, err := base64.StdEncoding.DecodeString(encodedStr); err == nil {
_, err := w.Write(audio)
return err
} else {
return err
}
_, err := io.Copy(w, base64.NewDecoder(base64.StdEncoding, strings.NewReader(encodedStr)))
return err
}
}
return errors.New("no audio content")

Loading…
Cancel
Save