mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
fix port field parsing. fixes #1684
This commit is contained in:
parent
d66c3896ed
commit
778767a125
@ -195,8 +195,11 @@ func (list *PortList) Build() *net.PortList {
|
|||||||
// UnmarshalJSON implements encoding/json.Unmarshaler.UnmarshalJSON
|
// UnmarshalJSON implements encoding/json.Unmarshaler.UnmarshalJSON
|
||||||
func (list *PortList) UnmarshalJSON(data []byte) error {
|
func (list *PortList) UnmarshalJSON(data []byte) error {
|
||||||
var listStr string
|
var listStr string
|
||||||
|
var number uint32
|
||||||
if err := json.Unmarshal(data, &listStr); err != nil {
|
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, ",")
|
rangelist := strings.Split(listStr, ",")
|
||||||
for _, rangeStr := range rangelist {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,10 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
"type": "field",
|
"type": "field",
|
||||||
"port": "53, 443, 1000-2000",
|
"port": "53, 443, 1000-2000",
|
||||||
"outboundTag": "test"
|
"outboundTag": "test"
|
||||||
|
},{
|
||||||
|
"type": "field",
|
||||||
|
"port": 123,
|
||||||
|
"outboundTag": "test"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -114,6 +118,16 @@ func TestRouterConfig(t *testing.T) {
|
|||||||
Tag: "test",
|
Tag: "test",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
PortList: &net.PortList{
|
||||||
|
Range: []*net.PortRange{
|
||||||
|
{From: 123, To: 123},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TargetTag: &router.RoutingRule_Tag{
|
||||||
|
Tag: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user