Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/couch/src/couch_doc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,16 @@ transfer_fields([{<<"_revisions">>, {Props}} | Rest], Doc, DbName) ->
true ->
ok
end,
[throw({doc_validation, "RevId isn't a string"}) ||
RevId <- RevIds, not is_binary(RevId)],
RevIds2 = [parse_revid(RevId) || RevId <- RevIds],
RevIds2 = lists:map(fun(RevId) ->
try
parse_revid(RevId)
catch
error:function_clause ->
throw({doc_validation, "RevId isn't a string"});
error:badarg ->
throw({doc_validation, "RevId isn't a valid hexadecimal"})
end
end, RevIds),
transfer_fields(Rest, Doc#doc{revs={Start, RevIds2}}, DbName);

transfer_fields([{<<"_deleted">>, B} | Rest], Doc, DbName) when is_boolean(B) ->
Expand Down
22 changes: 12 additions & 10 deletions src/couch/test/couch_doc_json_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ from_json_error_cases() ->
{doc_validation, "RevId isn't a string"},
"Revision ids must be strings."
},
{
{[{<<"_revisions">>, {[{<<"start">>, 0},
{<<"ids">>, [<<"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">>]}]}}]},
{doc_validation, "RevId isn't a valid hexadecimal"},
"Revision ids must be a valid hex."
},
{
{[{<<"_something">>, 5}]},
{doc_validation, <<"Bad special document member: _something">>},
Expand All @@ -288,18 +294,14 @@ from_json_error_cases() ->

lists:map(fun
({Fun, Expect, Msg}) when is_function(Fun, 0) ->
Error = (catch couch_doc:from_json_obj_validate(Fun())),
{Msg, ?_assertMatch(Expect, Error)};
{Msg,
?_assertThrow(Expect, couch_doc:from_json_obj_validate(Fun()))};
({EJson, Expect, Msg}) ->
Error = (catch couch_doc:from_json_obj_validate(EJson)),
{Msg, ?_assertMatch(Expect, Error)};
{Msg,
?_assertThrow(Expect, couch_doc:from_json_obj_validate(EJson))};
({EJson, Msg}) ->
try
couch_doc:from_json_obj_validate(EJson),
{"Conversion failed to raise an exception", ?_assert(false)}
catch
_:_ -> {Msg, ?_assert(true)}
end
{Msg,
?_assertThrow(_, couch_doc:from_json_obj_validate(EJson))}
end, Cases).

from_json_with_dbname_error_cases() ->
Expand Down