diff options
author | iilyak <iilyak@users.noreply.github.com> | 2021-05-06 04:47:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-06 04:47:51 -0700 |
commit | f130ae1c7ef8849da911f36861a8af32bc70e723 (patch) | |
tree | 30735fe442f700c1a74608362fa3f7658d47da02 | |
parent | b972f126c0266c88bc492ec13e7631a70fb5c1cd (diff) | |
parent | 19c9e237f8c02c172812fc44785dc5a2d9a8b76a (diff) | |
download | couchdb-f130ae1c7ef8849da911f36861a8af32bc70e723.tar.gz |
Merge pull request #3544 from cloudant/att-to-json-without-md5
Handle the case when md5 field is undefined
-rw-r--r-- | src/couch/src/couch_att.erl | 9 | ||||
-rw-r--r-- | src/couch/test/eunit/couch_doc_json_tests.erl | 13 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/couch/src/couch_att.erl b/src/couch/src/couch_att.erl index 9009b5226..06671aa40 100644 --- a/src/couch/src/couch_att.erl +++ b/src/couch/src/couch_att.erl @@ -331,7 +331,8 @@ digest_from_json(Props) -> end. -to_json(Att, OutputData, DataToFollow, ShowEncoding) -> +to_json(#{md5 := Md5} = Att, OutputData, DataToFollow, ShowEncoding) + when is_binary(Md5) -> #{ name := Name, type := Type, @@ -339,7 +340,6 @@ to_json(Att, OutputData, DataToFollow, ShowEncoding) -> disk_len := DiskLen, att_len := AttLen, revpos := RevPos, - md5 := Md5, encoding := Encoding } = Att, Props = [ @@ -371,7 +371,10 @@ to_json(Att, OutputData, DataToFollow, ShowEncoding) -> true -> [] end, - {Name, {Props ++ DigestProp ++ DataProps ++ EncodingProps}}. + {Name, {Props ++ DigestProp ++ DataProps ++ EncodingProps}}; + +to_json(#{md5 := undefined} = Att, OutputData, DataToFollow, ShowEncoding) -> + to_json(Att#{md5 => <<>>}, OutputData, DataToFollow, ShowEncoding). flush(Db, DocId, Att1) -> diff --git a/src/couch/test/eunit/couch_doc_json_tests.erl b/src/couch/test/eunit/couch_doc_json_tests.erl index 3a07642de..e2692d59c 100644 --- a/src/couch/test/eunit/couch_doc_json_tests.erl +++ b/src/couch/test/eunit/couch_doc_json_tests.erl @@ -430,6 +430,14 @@ to_json_success_cases() -> {data, <<"sammich">>}, {md5, <<>>}, {encoding, identity} + ]), + couch_att:new([ + {name, <<"animals.json">>}, + {type, <<"application/json">>}, + {revpos, 1}, + {data, <<"leon">>}, + {md5, undefined}, + {encoding, identity} ]) ]}, {[ @@ -444,6 +452,11 @@ to_json_success_cases() -> {<<"content_type">>, <<"application/food">>}, {<<"revpos">>, 1}, {<<"data">>, <<"c2FtbWljaA==">>} + ]}}, + {<<"animals.json">>, {[ + {<<"content_type">>, <<"application/json">>}, + {<<"revpos">>, 1}, + {<<"data">>, <<"bGVvbg==">>} ]}} ]}} ]}, |