Repository: couchdb-couch
Updated Branches:
  refs/heads/master f122f9429 -> 72869b8bf


Fix validation for ddoc name


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/3c090118
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/3c090118
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/3c090118

Branch: refs/heads/master
Commit: 3c090118775fa0080d18cf97285cf417bc4fce1a
Parents: f122f94
Author: Eric Avdey <e...@eiri.ca>
Authored: Thu Sep 1 09:51:14 2016 -0300
Committer: Eric Avdey <e...@eiri.ca>
Committed: Thu Sep 1 10:50:56 2016 -0300

----------------------------------------------------------------------
 src/couch_doc.erl        |  4 ++++
 test/couch_doc_tests.erl | 28 ++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/3c090118/src/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couch_doc.erl b/src/couch_doc.erl
index 11063d9..af14038 100644
--- a/src/couch_doc.erl
+++ b/src/couch_doc.erl
@@ -169,6 +169,10 @@ parse_revs(_) ->
 
 validate_docid(<<"">>) ->
     throw({illegal_docid, <<"Document id must not be empty">>});
+validate_docid(<<"_design/">>) ->
+    throw({illegal_docid, <<"Illegal document id `_design/`">>});
+validate_docid(<<"_local/">>) ->
+    throw({illegal_docid, <<"Illegal document id `_local/`">>});
 validate_docid(Id) when is_binary(Id) ->
     case couch_util:validate_utf8(Id) of
         false -> throw({illegal_docid, <<"Document id must be valid UTF-8">>});

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/3c090118/test/couch_doc_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_doc_tests.erl b/test/couch_doc_tests.erl
index 2025c25..fce4ff7 100644
--- a/test/couch_doc_tests.erl
+++ b/test/couch_doc_tests.erl
@@ -72,6 +72,34 @@ len_doc_to_multi_part_stream_test() ->
         couch_doc:len_doc_to_multi_part_stream(Boundary, JsonBytes, Atts, 
true),
     ok.
 
+validate_docid_test_() ->
+    {setup,
+        fun() ->
+            ok = meck:new(couch_db_plugin, [passthrough]),
+            meck:expect(couch_db_plugin, validate_docid, fun(_) -> false end)
+        end,
+        fun(_) ->
+            meck:unload(couch_db_plugin)
+        end,
+        [
+            ?_assertEqual(ok, couch_doc:validate_docid(<<"idx">>)),
+            ?_assertEqual(ok, couch_doc:validate_docid(<<"_design/idx">>)),
+            ?_assertEqual(ok, couch_doc:validate_docid(<<"_local/idx">>)),
+            ?_assertThrow({illegal_docid, _},
+                couch_doc:validate_docid(<<>>)),
+            ?_assertThrow({illegal_docid, _},
+                couch_doc:validate_docid(<<16#80>>)),
+            ?_assertThrow({illegal_docid, _},
+                couch_doc:validate_docid(<<"_idx">>)),
+            ?_assertThrow({illegal_docid, _},
+                couch_doc:validate_docid(<<"_">>)),
+            ?_assertThrow({illegal_docid, _},
+                couch_doc:validate_docid(<<"_design/">>)),
+            ?_assertThrow({illegal_docid, _},
+                couch_doc:validate_docid(<<"_local/">>))
+        ]
+    }.
+
 request(start) ->
     {ok, Doc} = file:read_file(?REQUEST_FIXTURE),
     {Doc, fun() -> request(stop) end};

Reply via email to