eiri commented on a change in pull request #1754: Do not use [] in
feature_flags configuration
URL: https://github.com/apache/couchdb/pull/1754#discussion_r235944452
##########
File path: src/couch/src/couch_flags_config.erl
##########
@@ -120,16 +121,29 @@ parse_flags(_Tokens, _) ->
[flag_id()] | {error, Reason :: term()}.
parse_flags_term(FlagsBin) ->
- case couch_util:parse_term(FlagsBin) of
- {ok, Flags} when is_list(Flags) ->
- lists:usort(Flags);
- Term ->
- {error, {
- "Flags should be list of atoms (got \"~s\"): ~p",
- [FlagsBin, Term]
- }}
+ {Flags, Errors} = lists:splitwith(fun erlang:is_atom/1,
+ [parse_flag(F) || F <- split_by_comma(FlagsBin)]),
+ case Errors of
+ [] ->
+ lists:usort(Flags);
+ _ ->
+ {error, {
+ "Cannot parse list of tags: ~n~p",
+ Errors
+ }}
end.
+split_by_comma(Binary) ->
+ case binary:split(Binary, <<",">>, [global]) of
+ [<<>>] -> [];
+ Tokens -> Tokens
+ end.
+
+parse_flag(FlagName) when size(FlagName) > ?MAX_FLAG_NAME_LENGTH ->
+ {too_long, FlagName};
+parse_flag(FlagName) ->
+ list_to_atom(string:strip(binary_to_list(FlagName))).
Review comment:
How about changing this into `list_to_existing_atom/1`, just to be super
safe? If I understand correctly a flag should be defined by this time, so that
should work. It can even act as a poor man's validator, if we wrap it in
something like `try ... catch _:_ -> {invalid_flag, FlagName}`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services