-
-
Notifications
You must be signed in to change notification settings - Fork 520
Closed
Description
Hi, thank you for the great work on this library!
I ran into an issue when using netutil.BuildUrl. Specifically, the hostRegex used for validating the host does not accept valid multi-level domain names such as:
host := "my.api.edu.cn"When calling:
func TestBuildUrl(t *testing.T) {
url, err := netutil.BuildUrl(
"https",
"my.api.edu.cn",
"/api",
map[string][]string{
"q": {"123"},
},
)
if err != nil {
t.Errorf("err %+v", err)
}
t.Logf("url %s:", url)
}It returns the following error:
build url error: invalid host: 'my.api.edu.cn' is not a valid host
After investigating the code, I found that the regular expression used for validating the host:
^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])(\.[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])*$only matches hosts like xxx.xx.com but fails for valid public suffixes such as .com.cn, .gov.cn, etc., which are widely used in countries like China.
Suggested Fix
Consider updating the hostRegex to support multi-level domain names like:
• api.test.gov.cn
• service.example.co.uk
• my.api.edu.cn
Thanks again for your work on this project!
Metadata
Metadata
Assignees
Labels
No labels