Disallow names that start with '.' in IsDomainName() (#1376)
* Disallow names that start with '.' in IsDomainName() * Also update packDomain()
This commit is contained in:
parent
5521648610
commit
7413c83334
|
@ -218,6 +218,11 @@ func IsDomainName(s string) (labels int, ok bool) {
|
|||
|
||||
wasDot = false
|
||||
case '.':
|
||||
if i == 0 && len(s) > 1 {
|
||||
// leading dots are not legal except for the root zone
|
||||
return labels, false
|
||||
}
|
||||
|
||||
if wasDot {
|
||||
// two dots back to back is not legal
|
||||
return labels, false
|
||||
|
|
|
@ -176,7 +176,10 @@ func TestIsDomainName(t *testing.T) {
|
|||
lab int
|
||||
}
|
||||
names := map[string]*ret{
|
||||
"..": {false, 1},
|
||||
".": {true, 1},
|
||||
"..": {false, 0},
|
||||
"double-dot..test": {false, 1},
|
||||
".leading-dot.test": {false, 0},
|
||||
"@.": {true, 1},
|
||||
"www.example.com": {true, 3},
|
||||
"www.e%ample.com": {true, 3},
|
||||
|
|
Loading…
Reference in New Issue