Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Commit 3492f6a

Browse files
authored
Allow altPath to be unspecified (#8)
Performing the validation on an empty URL will return `unexpected url format`. Also fix the spelling of superUsers in CONFIG.md.
1 parent 20c11b5 commit 3492f6a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

CONFIG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ status](https://help.github.com/articles/about-statuses/):
209209
Visit to `github.com/<user>/<repo>/settings/hooks` and create a new webhook.
210210

211211
- Payload URL: Use your worker IP address or hostname as the hook URL,
212-
`https://1.2.3.4/gohci/workerA?altPath=foo.io/x/project&superusers=user1,user2,user3`.
212+
`https://1.2.3.4/gohci/workerA?altPath=foo.io/x/project&superUsers=user1,user2,user3`.
213213
- `altPath`: Set it when using [canonical import
214214
path](https://golang.org/doc/go1.4#canonicalimports). For example,
215215
`periph.io/x/gohci`. Leave it unspecified otherwise, which should be the

cmd/gohci-worker/server.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,14 @@ func validateArgs(values url.Values) (string, []string, error) {
273273
if strings.Contains(altPath, "//") || strings.Contains(altPath, "..") {
274274
return "", nil, fmt.Errorf("invalid altPath %q: contains invalid characters", altPath)
275275
}
276-
u, err := url.Parse("https://" + altPath)
277-
if err != nil {
278-
return "", nil, fmt.Errorf("invalid altPath %q: %v", altPath, err)
279-
}
280-
if u.Scheme != "https" || u.User != nil || u.Host == "" || u.Path == "" || u.RawQuery != "" || u.Fragment != "" {
281-
return "", nil, fmt.Errorf("invalid altPath %q: unexpected url format", altPath)
276+
if len(altPath) > 0 {
277+
u, err := url.Parse("https://" + altPath)
278+
if err != nil {
279+
return "", nil, fmt.Errorf("invalid altPath %q: %v", altPath, err)
280+
}
281+
if u.Scheme != "https" || u.User != nil || u.Host == "" || u.Path == "" || u.RawQuery != "" || u.Fragment != "" {
282+
return "", nil, fmt.Errorf("invalid altPath %q: unexpected url format", altPath)
283+
}
282284
}
283285
var superUsers []string
284286
for _, v := range values["superUsers"] {

0 commit comments

Comments
 (0)