Skip to content

Commit

Permalink
(fix) handle spaces in the file reader
Browse files Browse the repository at this point in the history
  • Loading branch information
leonjza committed Sep 19, 2024
1 parent d430730 commit fd9f55f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/readers/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (fr *FileReader) Read(ch chan<- string) error {
// If any ports configuration exists, those will also be added as candidates.
func (fr *FileReader) urlsFor(candidate string, ports []int) []string {
var urls []string

// trim any spaces
candidate = strings.TrimSpace(candidate)

// check if we got a scheme, add
hasScheme := strings.Contains(candidate, "://")
if !hasScheme {
Expand Down
9 changes: 9 additions & 0 deletions pkg/readers/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ func TestUrlsFor(t *testing.T) {
"https://192.168.1.1:8080",
},
},
{
name: "Test with IP and port with spaces",
candidate: " 192.168.1.1:8080 ",
ports: []int{80, 443, 8443},
want: []string{
"http://192.168.1.1:8080",
"https://192.168.1.1:8080",
},
},
{
name: "Test with scheme, IP and port",
candidate: "http://192.168.1.1:8080",
Expand Down

0 comments on commit fd9f55f

Please sign in to comment.