-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ip_port schema type crash #11077
Changes from all commits
45963b6
a4be9b8
07172e4
093cdab
856de78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1758,7 +1758,7 @@ base_listener(Bind) -> | |
)}, | ||
{"bind", | ||
sc( | ||
hoconsc:union([ip_port(), integer()]), | ||
ip_port(), | ||
#{ | ||
default => Bind, | ||
required => true, | ||
|
@@ -2418,21 +2418,21 @@ mk_duration(Desc, OverrideMeta) -> | |
to_duration(Str) -> | ||
case hocon_postprocess:duration(Str) of | ||
I when is_integer(I) -> {ok, I}; | ||
_ -> {error, Str} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hocon 0.39.9 has fixed a issue:
|
||
_ -> to_integer(Str) | ||
end. | ||
|
||
to_duration_s(Str) -> | ||
case hocon_postprocess:duration(Str) of | ||
I when is_number(I) -> {ok, ceiling(I / 1000)}; | ||
_ -> {error, Str} | ||
_ -> to_integer(Str) | ||
end. | ||
|
||
-spec to_duration_ms(Input) -> {ok, integer()} | {error, Input} when | ||
Input :: string() | binary(). | ||
to_duration_ms(Str) -> | ||
case hocon_postprocess:duration(Str) of | ||
I when is_number(I) -> {ok, ceiling(I)}; | ||
_ -> {error, Str} | ||
_ -> to_integer(Str) | ||
end. | ||
|
||
-spec to_timeout_duration(Input) -> {ok, timeout_duration()} | {error, Input} when | ||
|
@@ -2473,7 +2473,7 @@ do_to_timeout_duration(Str, Fn, Max, Unit) -> | |
to_bytesize(Str) -> | ||
case hocon_postprocess:bytesize(Str) of | ||
I when is_integer(I) -> {ok, I}; | ||
_ -> {error, Str} | ||
_ -> to_integer(Str) | ||
end. | ||
|
||
to_wordsize(Str) -> | ||
|
@@ -2483,6 +2483,13 @@ to_wordsize(Str) -> | |
Error -> Error | ||
end. | ||
|
||
to_integer(Str) -> | ||
case string:to_integer(Str) of | ||
{Int, []} -> {ok, Int}; | ||
{Int, <<>>} -> {ok, Int}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have another function clause There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I will remove is_list |
||
_ -> {error, Str} | ||
end. | ||
|
||
to_percent(Str) -> | ||
{ok, hocon_postprocess:percent(Str)}. | ||
|
||
|
@@ -2525,9 +2532,9 @@ to_ip_port(Str) -> | |
case split_ip_port(Str) of | ||
{"", Port} -> | ||
%% this is a local address | ||
{ok, list_to_integer(Port)}; | ||
{ok, parse_port(Port)}; | ||
{MaybeIp, Port} -> | ||
PortVal = list_to_integer(Port), | ||
PortVal = parse_port(Port), | ||
case inet:parse_address(MaybeIp) of | ||
{ok, IpTuple} -> | ||
{ok, {IpTuple, PortVal}}; | ||
|
@@ -2543,18 +2550,11 @@ split_ip_port(Str0) -> | |
case lists:split(string:rchr(Str, $:), Str) of | ||
%% no colon | ||
{[], Str} -> | ||
try | ||
%% if it's just a port number, then return as-is | ||
_ = list_to_integer(Str), | ||
{"", Str} | ||
catch | ||
_:_ -> | ||
error | ||
end; | ||
{"", Str}; | ||
{IpPlusColon, PortString} -> | ||
IpStr0 = lists:droplast(IpPlusColon), | ||
case IpStr0 of | ||
%% dropp head/tail brackets | ||
%% drop head/tail brackets | ||
[$[ | S] -> | ||
case lists:last(S) of | ||
$] -> {lists:droplast(S), PortString}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove integer: ip_port() also support setting as
1883
.