This is an automated email from the ASF dual-hosted git repository. rnewson pushed a commit to branch user-partitioned-dbs-4 in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 09ddfeb4eda6299b08755541eee3e4065e37c83e Author: Robert Newson <[email protected]> AuthorDate: Thu Aug 2 14:41:03 2018 +0100 Enforce partition:id format in doc ids --- src/chttpd/src/chttpd_db.erl | 1 + src/couch/src/couch_doc.erl | 18 ++++++++++++++---- src/couch/test/fixtures/test.couch | Bin 16482 -> 0 bytes 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl index 0905559..b1118f8 100644 --- a/src/chttpd/src/chttpd_db.erl +++ b/src/chttpd/src/chttpd_db.erl @@ -710,6 +710,7 @@ db_doc_req(#httpd{method='GET', mochi_req=MochiReq}=Req, Db, DocId) -> options = Options0, atts_since = AttsSince } = parse_doc_query(Req), + couch_doc:validate_docid(DocId, couch_db:name(Db)), Options = [{user_ctx, Req#httpd.user_ctx} | Options0], case Revs of [] -> diff --git a/src/couch/src/couch_doc.erl b/src/couch/src/couch_doc.erl index f960ec5..963f359 100644 --- a/src/couch/src/couch_doc.erl +++ b/src/couch/src/couch_doc.erl @@ -199,11 +199,21 @@ parse_revs(_) -> validate_docid(DocId, DbName) -> - case DbName =:= ?l2b(config:get("mem3", "shards_db", "_dbs")) andalso - lists:member(DocId, ?SYSTEM_DATABASES) of - true -> + SystemId = DbName =:= ?l2b(config:get("mem3", "shards_db", "_dbs")) andalso + lists:member(DocId, ?SYSTEM_DATABASES), + Partitioned = is_binary(DbName) andalso mem3:is_partitioned(DbName), + case {SystemId, Partitioned} of + {true, _} -> ok; - false -> + {false, true} -> + case binary:split(DocId, <<":">>) of + [Partition, Rest] -> + ok = validate_docid(Partition), + validate_docid(Rest); + _ -> + throw({illegal_docid, <<"doc id must be of form partition:id">>}) + end; + {false, false} -> validate_docid(DocId) end. diff --git a/src/couch/test/fixtures/test.couch b/src/couch/test/fixtures/test.couch deleted file mode 100644 index 32c79af..0000000 Binary files a/src/couch/test/fixtures/test.couch and /dev/null differ
