fix: fix extension-check logic when normalizing github URLs (#158)
This commit is contained in:
@ -142,7 +142,7 @@ func SourceFromURL(u *url.URL, encoding TemplateEncoding) TemplateSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
normalized := github.NormalizeURLToContent(u, "yaml", "yml", "jsonnet", "json").String()
|
normalized := github.NormalizeURLToContent(u, ".yaml", ".yml", ".jsonnet", ".json").String()
|
||||||
|
|
||||||
return TemplateSource{
|
return TemplateSource{
|
||||||
Name: normalized,
|
Name: normalized,
|
||||||
|
@ -37,7 +37,7 @@ func NormalizeURLToContent(u *url.URL, extensions ...string) *url.URL {
|
|||||||
func extensionMatches(u *url.URL, extensions []string) bool {
|
func extensionMatches(u *url.URL, extensions []string) bool {
|
||||||
ext := path.Ext(u.Path)
|
ext := path.Ext(u.Path)
|
||||||
for _, e := range extensions {
|
for _, e := range extensions {
|
||||||
if strings.EqualFold(e, "."+ext) {
|
if strings.EqualFold(ext, e) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,12 @@ func TestNormalize(t *testing.T) {
|
|||||||
in: url.URL{Host: "github.com", Path: "/influxdata/influxdb/blob/master/flags.yml"},
|
in: url.URL{Host: "github.com", Path: "/influxdata/influxdb/blob/master/flags.yml"},
|
||||||
out: url.URL{Host: "raw.githubusercontent.com", Path: "/influxdata/influxdb/master/flags.yml"},
|
out: url.URL{Host: "raw.githubusercontent.com", Path: "/influxdata/influxdb/master/flags.yml"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "github URL with extensions",
|
||||||
|
in: url.URL{Host: "github.com", Path: "/influxdata/community-templates/blob/master/github/github.yml"},
|
||||||
|
exts: []string{".yaml", ".yml", ".jsonnet", ".json"},
|
||||||
|
out: url.URL{Host: "raw.githubusercontent.com", Path: "/influxdata/community-templates/master/github/github.yml"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "other URL",
|
name: "other URL",
|
||||||
in: url.URL{Host: "google.com", Path: "/fake.yml"},
|
in: url.URL{Host: "google.com", Path: "/fake.yml"},
|
||||||
@ -30,7 +36,7 @@ func TestNormalize(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "github URL - wrong extension",
|
name: "github URL - wrong extension",
|
||||||
in: url.URL{Host: "github.com", Path: "/influxdata/influxdb/blob/master/flags.yml"},
|
in: url.URL{Host: "github.com", Path: "/influxdata/influxdb/blob/master/flags.yml"},
|
||||||
exts: []string{"json"},
|
exts: []string{".json"},
|
||||||
out: url.URL{Host: "github.com", Path: "/influxdata/influxdb/blob/master/flags.yml"},
|
out: url.URL{Host: "github.com", Path: "/influxdata/influxdb/blob/master/flags.yml"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user