Skip to content

Commit 1c2f62c

Browse files
committed
Construct URL query string using net/url URL type
1 parent 2d3b0ff commit 1c2f62c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

routes/doi.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"crypto/cipher"
66
"crypto/rand"
77
"encoding/base64"
8-
"fmt"
98
"io"
109
"net/http"
10+
"net/url"
1111

1212
"github.com/G-Node/gogs/pkg/context"
1313
"github.com/G-Node/gogs/pkg/setting"
@@ -22,12 +22,23 @@ func RequestDOI(c *context.Context) {
2222
token := c.GetCookie(setting.SessionConfig.CookieName)
2323
token, err := encrypt([]byte(setting.DOI.Key), token)
2424
if err != nil {
25-
log.Error(2, "Could not encrypt Secret key: %s", err)
25+
log.Error(2, "Could not encrypt secret key: %s", err)
2626
c.Status(http.StatusInternalServerError)
2727
return
2828
}
29-
url := fmt.Sprintf("%s/register?repo=%s&user=%s&token=%s", setting.DOI.URL, c.Repo.Repository.FullName(), c.User.Name, token)
30-
c.Redirect(url)
29+
doiurl, err := url.Parse(setting.DOI.URL + "/register") // TODO: Handle error by notifying admin email
30+
if err != nil {
31+
log.Error(2, "Failed to parse DOI URL: %s", setting.DOI.URL)
32+
}
33+
34+
params := url.Values{}
35+
params.Add("repo", c.Repo.Repository.FullName())
36+
params.Add("user", c.User.Name)
37+
params.Add("token", token)
38+
doiurl.RawQuery = params.Encode()
39+
target, _ := url.PathUnescape(doiurl.String())
40+
log.Trace(target)
41+
c.RawRedirect(target)
3142
}
3243

3344
// NOTE: TEMPORARY COPY FROM gin-doi

0 commit comments

Comments
 (0)