Skip to content

Commit

Permalink
Merge pull request v2ray#1685 from eycorsican/fix-port
Browse files Browse the repository at this point in the history
fix port field parsing. fixes v2ray#1684
  • Loading branch information
kslr authored May 15, 2019
2 parents d66c389 + 778767a commit 2544c2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion infra/conf/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
14 changes: 14 additions & 0 deletions infra/conf/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func TestRouterConfig(t *testing.T) {
"type": "field",
"port": "53, 443, 1000-2000",
"outboundTag": "test"
},{
"type": "field",
"port": 123,
"outboundTag": "test"
}
]
},
Expand Down Expand Up @@ -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",
},
},
},
},
},
Expand Down

0 comments on commit 2544c2f

Please sign in to comment.