Skip to content

Commit

Permalink
add a sanitized version of the hostname (replace any character matchi…
Browse files Browse the repository at this point in the history
…ng [^a-zA-Z0-9\-.] with underscore)

fixes txn2#240
  • Loading branch information
hosswald committed Sep 7, 2022
1 parent c811b22 commit 095ad06
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/fwdport/fwdport.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"
"net/http"
"regexp"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -248,6 +249,13 @@ func (pfo *PortForwardOpts) addHost(host string) {

// add host to /etc/hosts
pfo.HostFile.Hosts.AddHost(pfo.LocalIp.String(), host)

// replace illegal characters with underscore and add another entry if this changes the hostname
hostnameIllegalChars := regexp.MustCompile(`[^a-zA-Z0-9\-.]`)
sanitizedHost := hostnameIllegalChars.ReplaceAllString(host, `_`)
if host != sanitizedHost {
pfo.addHost(sanitizedHost) //should recurse only once
}
}

// AddHosts adds hostname entries to /etc/hosts
Expand Down

0 comments on commit 095ad06

Please sign in to comment.