You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2014/10/13 19:47:11 UTC

couch commit: updated refs/heads/master to ed36032

Repository: couchdb-couch
Updated Branches:
  refs/heads/master 46cb6a4cd -> ed360325c


Respond with HTTP 400 Bad Request on invalid revision number

CouchDB should return HTTP 400 instead of HTTP 500 response
when revision number isn't integer like "foo-bar" as like as it does
for completely invalid revisions like "foo".

COUCHDB-2375


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

Branch: refs/heads/master
Commit: ed360325cacbc3f5320b28f3c42ef2bc3ca3c716
Parents: 46cb6a4
Author: Alexander Shorin <kx...@apache.org>
Authored: Fri Oct 10 22:00:03 2014 +0400
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Oct 13 21:25:21 2014 +0400

----------------------------------------------------------------------
 src/couch_doc.erl        |  8 +++++++-
 test/couch_doc_tests.erl | 22 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ed360325/src/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couch_doc.erl b/src/couch_doc.erl
index de3141d..6fc9b09 100644
--- a/src/couch_doc.erl
+++ b/src/couch_doc.erl
@@ -140,7 +140,13 @@ parse_rev(Rev) when is_binary(Rev) ->
 parse_rev(Rev) when is_list(Rev) ->
     SplitRev = lists:splitwith(fun($-) -> false; (_) -> true end, Rev),
     case SplitRev of
-        {Pos, [$- | RevId]} -> {list_to_integer(Pos), parse_revid(RevId)};
+        {Pos, [$- | RevId]} ->
+            IntPos = try list_to_integer(Pos) of
+                Val -> Val
+            catch
+                error:badarg -> throw({bad_request, <<"Invalid rev format">>})
+            end,
+            {IntPos, parse_revid(RevId)};
         _Else -> throw({bad_request, <<"Invalid rev format">>})
     end;
 parse_rev(_BadRev) ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ed360325/test/couch_doc_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_doc_tests.erl b/test/couch_doc_tests.erl
new file mode 100644
index 0000000..ca944dc
--- /dev/null
+++ b/test/couch_doc_tests.erl
@@ -0,0 +1,22 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_doc_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+
+
+parse_rev_test() ->
+    ?assertEqual({1, <<"123">>}, couch_doc:parse_rev("1-123")),
+    ?assertEqual({1, <<"123">>}, couch_doc:parse_rev(<<"1-123">>)),
+    ?assertException(throw, {bad_request, _}, couch_doc:parse_rev("1f-123")),
+    ?assertException(throw, {bad_request, _}, couch_doc:parse_rev("bar")).