tools: Fix LoadCredentials()

If the URL ends in a slash, this would fail to match the gitcookies file

Change-Id: I987ec637b2f6db172d4173938960060321722bfe
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87920
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2022-04-26 14:53:42 +00:00 committed by Dawn LUCI CQ
parent 1d882f55b7
commit 1c3f88eb0c
1 changed files with 2 additions and 2 deletions

View File

@ -80,8 +80,8 @@ func (p *Patchset) RegisterFlags(defaultHost, defaultProject string) {
func LoadCredentials(url string) Credentials {
cookiesFile := os.Getenv("HOME") + "/.gitcookies"
if cookies, err := ioutil.ReadFile(cookiesFile); err == nil {
url := strings.TrimPrefix(url, "https://")
re := regexp.MustCompile(url + `\s+(?:FALSE|TRUE)[\s/]+(?:FALSE|TRUE)\s+[0-9]+\s+.\s+(.*)=(.*)`)
url := strings.TrimSuffix(strings.TrimPrefix(url, "https://"), "/")
re := regexp.MustCompile(url + `/?\s+(?:FALSE|TRUE)[\s/]+(?:FALSE|TRUE)\s+[0-9]+\s+.\s+(.*)=(.*)`)
match := re.FindStringSubmatch(string(cookies))
if len(match) == 3 {
return Credentials{match[1], match[2]}