Browse Source

Merge pull request #1685 from eycorsican/fix-port

fix port field parsing. fixes #1684
pull/2386/head^2
Kslr 6 years ago committed by GitHub
parent
commit
2544c2f8f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      infra/conf/common.go
  2. 14
      infra/conf/router_test.go

8
infra/conf/common.go

@ -195,8 +195,11 @@ func (list *PortList) Build() *net.PortList {
// UnmarshalJSON implements encoding/json.Unmarshaler.UnmarshalJSON
func (list *PortList) UnmarshalJSON(data []byte) error {
var listStr string
var number uint32
if err := json.Unmarshal(data, &listStr); err != nil {
return newError("invalid port list: ", string(data)).Base(err)
if err2 := json.Unmarshal(data, &number); err2 != nil {
return newError("invalid port: ", string(data)).Base(err2)
}
}
rangelist := strings.Split(listStr, ",")
for _, rangeStr := range rangelist {
@ -217,6 +220,9 @@ func (list *PortList) UnmarshalJSON(data []byte) error {
}
}
}
if number != 0 {
list.Range = append(list.Range, PortRange{From: uint32(number), To: uint32(number)})
}
return nil
}

14
infra/conf/router_test.go

@ -48,6 +48,10 @@ func TestRouterConfig(t *testing.T) {
"type": "field",
"port": "53, 443, 1000-2000",
"outboundTag": "test"
},{
"type": "field",
"port": 123,
"outboundTag": "test"
}
]
},
@ -114,6 +118,16 @@ func TestRouterConfig(t *testing.T) {
Tag: "test",
},
},
{
PortList: &net.PortList{
Range: []*net.PortRange{
{From: 123, To: 123},
},
},
TargetTag: &router.RoutingRule_Tag{
Tag: "test",
},
},
},
},
},

Loading…
Cancel
Save