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 4e5f150
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 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 @@ -190,21 +191,28 @@ 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")
}
}

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

func shouldBeEmpty(name string) string {
return fmt.Sprintf("%s should be empty", name)
}
Expand Down

0 comments on commit 4e5f150

Please sign in to comment.