Skip to content

Commit

Permalink
escape
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed May 8, 2020
1 parent 7ea2965 commit 35c006b
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions cmd/checker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"sort"
"strings"

"github.com/cdnjs/tools/npm"
"github.com/cdnjs/tools/packages"
Expand Down Expand Up @@ -59,10 +60,7 @@ func showFiles(path string) {
return
}

fmt.Printf("Preview for `%s`\n", path)

if pckg.Autoupdate == nil || pckg.Autoupdate.Source != "npm" {
fmt.Println(pckg.Autoupdate)
err(ctx, "unsupported autoupdate")
return
}
Expand All @@ -81,19 +79,20 @@ func showFiles(path string) {

// print info for the first version
firstNpmVersion := npmVersions[0]
fmt.Printf("Last version (%s):\n", firstNpmVersion.Version)
{
tarballDir := npm.DownloadTar(ctx, firstNpmVersion.Tarball)
filesToCopy := pckg.NpmFilesFrom(tarballDir)

if len(filesToCopy) == 0 {
err(ctx, "No files will be published for this version; you can debug using")
errormsg := ""
errormsg += fmt.Sprintf("No files will be published for version %s.\n", firstNpmVersion.Version)

for _, filemap := range pckg.NpmFileMap {
for _, pattern := range filemap.Files {
fmt.Printf("[Click here to debug your glob pattern `%s`](%s).\n", pattern, makeGlobDebugLink(pattern, tarballDir))
errormsg += fmt.Sprintf("[Click here to debug your glob pattern `%s`](%s).\n", pattern, makeGlobDebugLink(pattern, tarballDir))
}
}
err(ctx, errormsg)
goto moreversions
}

Expand Down Expand Up @@ -190,18 +189,18 @@ func lintPackage(path string) {

func err(ctx context.Context, s string) {
if prefix, ok := ctx.Value("loggerPrefix").(string); ok {
fmt.Printf("::error file=%s,line=1,col=1::%s\n", prefix, s)
fmt.Printf("::error file=%s,line=1,col=1::%s\n", prefix, escapeGitHub(s))
} else {
fmt.Printf("error: %s\n", s)
panic("unreachable")
}
errCount += 1
}

func warn(ctx context.Context, s string) {
if prefix, ok := ctx.Value("loggerPrefix").(string); ok {
fmt.Printf("::warning file=%s,line=1,col=1::%s\n", prefix, s)
fmt.Printf("::warning file=%s,line=1,col=1::%s\n", prefix, escapeGitHub(s))
} else {
fmt.Printf("warning: %s\n", s)
panic("unreachable")
}
}

Expand All @@ -212,3 +211,10 @@ func shouldBeEmpty(name string) string {
func shouldNotBeEmpty(name string) string {
return fmt.Sprintf("%s should be specified", name)
}

func escapeGitHub(s string) string {
s = strings.ReplaceAll(s, "%", "%25")
s = strings.ReplaceAll(s, "\n", "%0A")
s = strings.ReplaceAll(s, "\r", "%0D")
return s
}

0 comments on commit 35c006b

Please sign in to comment.