Skip to content

Commit

Permalink
Merge pull request #11 from italia/fix/pe-161
Browse files Browse the repository at this point in the history
External url validation is less stricter and accept not only raw URLs
  • Loading branch information
sebbalex authored Jun 8, 2020
2 parents 31dd328 + 3bd040d commit 66e39c3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ func getRawURL(url *url.URL) string {
return ""
}

// getRawFile returns a valid raw file for
// major code hosting platforms
func getRawFile(urlString string) string {
url, err := url.Parse(urlString)
if err != nil {
return urlString
}
rawURL := vcsurl.GetRawFile(url)
if rawURL != nil {
return rawURL.String()
}
return ""
}

// parse returns new parsed and validated buffer and errors if any
func (app *App) parse(b []byte) ([]byte, error, error) {
url := getURLFromYMLBuffer(b)
Expand All @@ -129,7 +143,7 @@ func (app *App) parse(b []byte) ([]byte, error, error) {
func (app *App) parseRemoteURL(urlString string) ([]byte, error, error) {
log.Infof("called parseRemoteURL() url: %s", urlString)
p := publiccode.NewParser()
errParse := p.ParseRemoteFile(urlString)
errParse := p.ParseRemoteFile(getRawFile(urlString))
pc, err := p.ToYAML()

return pc, errParse, err
Expand Down

0 comments on commit 66e39c3

Please sign in to comment.