diff options
author | Garren Smith <garren.smith@gmail.com> | 2018-09-06 15:31:26 +0200 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2018-09-07 16:37:28 +0100 |
commit | ab7e854d68d8981aac3d91f50ef43eeb83afda20 (patch) | |
tree | 6cc4ddb39ea77de58d9fc70c142aa08a1d4d5ec9 | |
parent | 90a0028a676b0b04025b6afbcd895fb0a4389452 (diff) | |
download | couchdb-ab7e854d68d8981aac3d91f50ef43eeb83afda20.tar.gz |
validate docs for _bulk_get and _bulk_docs
-rw-r--r-- | src/chttpd/src/chttpd_db.erl | 15 | ||||
-rw-r--r-- | src/couch/src/couch_doc.erl | 2 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl index 3fe26a172..7707d1203 100644 --- a/src/chttpd/src/chttpd_db.erl +++ b/src/chttpd/src/chttpd_db.erl @@ -471,7 +471,8 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req, true -> Docs = lists:map( fun(JsonObj) -> - Doc = couch_doc:from_json_obj_validate(JsonObj), + DbName = couch_db:name(Db), + Doc = couch_doc:from_json_obj_validate(JsonObj, DbName), validate_attachment_names(Doc), Id = case Doc#doc.id of <<>> -> couch_uuids:new(); @@ -1701,7 +1702,7 @@ bulk_get_open_doc_revs(Db, {Props}, Options) -> bulk_get_open_doc_revs1(Db, Props, Options, {}) -> - case parse_field(<<"id">>, couch_util:get_value(<<"id">>, Props)) of + case parse_id_field(couch_util:get_value(<<"id">>, Props), Db) of {error, {DocId, Error, Reason}} -> {DocId, {error, {null, Error, Reason}}, Options}; @@ -1750,16 +1751,18 @@ bulk_get_open_doc_revs1(Db, Props, _, {DocId, Revs, Options}) -> end. -parse_field(<<"id">>, undefined) -> +parse_id_field(undefined, _Db) -> {ok, undefined}; -parse_field(<<"id">>, Value) -> +parse_id_field(Value, Db) -> try - ok = couch_doc:validate_docid(Value), + ok = validate_docid(Value, couch_db:name(Db)), {ok, Value} catch throw:{Error, Reason} -> {error, {Value, Error, Reason}} - end; + end. + + parse_field(<<"rev">>, undefined) -> {ok, undefined}; parse_field(<<"rev">>, Value) -> diff --git a/src/couch/src/couch_doc.erl b/src/couch/src/couch_doc.erl index f821696e8..135effddf 100644 --- a/src/couch/src/couch_doc.erl +++ b/src/couch/src/couch_doc.erl @@ -221,7 +221,7 @@ validate_docid(DocId, DbName, Options) -> case binary:split(DocId, <<":">>) of [<<"_design/", _/binary>> | _Rest] -> validate_docid(DocId); - [Partition, Rest] -> + [Partition, Rest] when Rest =/= <<>> -> ok = validate_docid(Partition), validate_docid(Rest); _ -> |