Skip to content

Commit

Permalink
netscape export: remove init condition from loop
Browse files Browse the repository at this point in the history
  • Loading branch information
srlehn committed Oct 31, 2020
1 parent 006930e commit d7671ad
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions export.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,40 @@ const httpOnlyPrefix = `#HttpOnly_`
//
// curl, wget, ... use this format.
func ExportCookies(w io.Writer, cookies []*Cookie) {
var isInit bool
for _, cookie := range cookies {
if len(cookies) < 1 {
return
}
var j int
for i, cookie := range cookies {
if cookie == nil {
continue
}
if !isInit {
fmt.Fprint(w, "# HTTP Cookie File\n\n")
isInit = true
fmt.Fprint(w, "# HTTP Cookie File\n\n")
j = i
break
}

for i := j; i < len(cookies); i++ {
if cookies[i] == nil {
continue
}

var domain string
if cookie.HttpOnly {
if cookies[i].HttpOnly {
domain = httpOnlyPrefix
}
domain += cookie.Domain
domain += cookies[i].Domain

fmt.Fprintf(
w,
"%s\t%s\t%s\t%s\t%d\t%s\t%s\n",
domain,
netscapeBool(strings.HasPrefix(cookie.Domain, `.`)),
cookie.Path,
netscapeBool(cookie.Secure),
cookie.Expires.Unix(),
cookie.Name,
cookie.Value,
netscapeBool(strings.HasPrefix(cookies[i].Domain, `.`)),
cookies[i].Path,
netscapeBool(cookies[i].Secure),
cookies[i].Expires.Unix(),
cookies[i].Name,
cookies[i].Value,
)
}
}
Expand Down

0 comments on commit d7671ad

Please sign in to comment.