From 6d2e39b47b4b136030675a0539d33cacddccca3d Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Tue, 19 Dec 2017 11:24:22 +0700 Subject: [PATCH] Minor change to chromedp-proxy to remove non-identifier characters in log names --- cmd/chromedp-proxy/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/chromedp-proxy/main.go b/cmd/chromedp-proxy/main.go index bb12b97..4d92173 100644 --- a/cmd/chromedp-proxy/main.go +++ b/cmd/chromedp-proxy/main.go @@ -21,6 +21,7 @@ import ( "net/url" "os" "path" + "regexp" "github.com/gorilla/websocket" ) @@ -170,11 +171,15 @@ func checkVersion() ([]byte, error) { return body, nil } +var ( + cleanRE = regexp.MustCompile(`[^a-zA-Z0-9_\-\.]`) +) + func createLog(id string) (io.Closer, *log.Logger) { var f io.Closer var w io.Writer = os.Stdout if !*flagNoLog && *flagLogMask != "" { - l, err := os.OpenFile(fmt.Sprintf(*flagLogMask, id), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) + l, err := os.OpenFile(fmt.Sprintf(*flagLogMask, cleanRE.ReplaceAllString(id, "")), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) if err != nil { log.Fatal(err) }