-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adresss does not support non fdqn domain #18
Comments
Ok, issues seems with Following patern works better:
or below if you prefer to have the initial / in the path
Tested with some samples from https://mathiasbynens.be/demo/url-regex - it should work for most of the basic url we can have (except unicode signs, non occidental letters) Would it be ok for you ? I'm not a golang dev, so I don't make a PR |
Ok, so learning by doing, I would propose something like below, feel free to comment :) package main
import (
"regexp"
"strconv"
)
const regexAddressConn string = `^([a-z]{3,}):\/\/([a-zA-Z0-9\.\-_]+):?([0-9]*)*([a-zA-Z0-9\/\.\-_\(\)?=&#%]*)*$`
// Connection data
type Connection struct {
Type string
Scheme string
Port int
Host string
Path string
}
// BuildConn build a connection structure.
// This connection data can later be used as a common structure
// by the functions that will check if the target is available.
func BuildConn(cfg *Config) *Connection {
if cfg.Host != "" {
return &Connection{Type: "tcp", Host: cfg.Host, Port: cfg.Port}
}
address := cfg.Address
if address == "" {
return nil
}
match := regexp.MustCompile(regexAddressConn).FindAllStringSubmatch(address, -1)
if len(match) < 1 {
return nil
}
res := match[0]
conn := &Connection{
Type: res[1],
Host: res[2],
Path: res[4],
}
if conn.Type != "tcp" {
conn.Scheme = conn.Type
conn.Type = "tcp"
}
// resolve port
if len(res[3]) == 0 {
if conn.Scheme == "https" {
conn.Port = 443
} else {
conn.Port = 80
}
} else {
if port, err := strconv.Atoi(res[3]); err == nil {
conn.Port = port
}
}
return conn
} I may still miss something as output remains the same :( I build a side code with the code I modified and when I print conn, I have: For URL:
So I don't understand why it fails at the program level :( |
Hmm when I put all the code in one single file, it works as expected 🙄 However, when I do in your code folder :
So maybe the issue is here ? |
Ok forget it ; a simple |
@maxcnunes Hi, could you please merge #19? |
Hi,
Testing withing docker, I was to do:
but waitforit reports:
Would it be possible to have a more flexible approach to valide domains ?
Thanks,
Nicolas
The text was updated successfully, but these errors were encountered: