Primitive types, duplicate values and wpart_valid
Roberto Aloi <roberto.aloi <at> erlang-solutions.com>
2010-12-07 19:04:15 GMT
Hi all,
I have a user-defined primitive type who relies on double entries in the POST list during validation. The
type is more or less in the same situation as the wtype_password, which is expected to receive one or two
POST variables with the same name (for confirmation purposes).
If this was working in Erlang Web 1.3, it doesn't work with Erlang Web 1.4 anymore. This is due to the
wpart_valid:zip_get/4 function, which removes every duplicate entry, making exceptions for the
password and collection types.
-spec(zip_get/4 :: (list(tuple()), list(string()),
list(tuple()), list(tuple())) -> list(tuple())).
zip_get([],[],_,Acc)->
lists:reverse(Acc);
zip_get([{collection, _}|T1],[H2|T2], POST, Acc) ->
In = proplists:get_all_values(H2,POST),
zip_get(T1,T2,POST,[In|Acc]);
zip_get([{password, _}|T1], [H2|T2], POST, Acc) ->
case proplists:get_all_values(H2, POST) of
[_, _] = Val ->
zip_get(T1, T2, POST, [Val|Acc]);
[Val] ->
zip_get(T1, T2, POST, [Val|Acc]);
_ ->
zip_get(T1, T2, POST, [undefined|Acc])
end;
zip_get([_|T1],[H2|T2], POST, Acc) ->
In = proplists:get_value(H2,POST),
zip_get(T1,T2,POST,[In|Acc]).
Notice the get_value in the last clause, as opposite to get_all_values, which I think it was the default
behaviour of earlier versions of Erlang Web. It can't simply replaced into a get_all_values since that
will break all others data types (such as wtype_time) which rely on exactly one element for validation.
Is there any reason why this behaviour was changed?
Cheers,
Roberto Aloi
--
--
University of Kent - Erlang Solutions Ltd.
Blog: http://aloiroberto.wordpress.com
Twitter: <at> prof3ta
------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d