diff options
author | ILYA Khlopotov <iilyak@apache.org> | 2021-05-04 13:14:50 -0700 |
---|---|---|
committer | ILYA Khlopotov <iilyak@apache.org> | 2021-05-06 03:24:12 -0700 |
commit | 19c9e237f8c02c172812fc44785dc5a2d9a8b76a (patch) | |
tree | a51e840593e5bbc3c935cb63cf90bc9e6c8a55a1 | |
parent | 7b71b4afa21036ed696b3cce45ae341791c34540 (diff) | |
download | couchdb-19c9e237f8c02c172812fc44785dc5a2d9a8b76a.tar.gz |
Handle the case when md5 field is undefined
Previously the default value for md5 field was `<<>>`. This value changed to
undefined when we switch to using maps instead of erlang records.
The change break the `couch_att:to_json/4` funciton because `base64:encode/1`
cannot handle atom `undefined`.
The issue happens for inline attachments only this is why it wasn't discovered
earlier.
-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==">>} ]}} ]}} ]}, |