You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2014/01/22 15:33:22 UTC

[1/3] couchdb commit: updated refs/heads/master to 37c8459

Updated Branches:
  refs/heads/master 15f4fff02 -> 37c845969


Move addition of qs params after normalization

This refactor executes normalize_path/1 before appending the bound query
string parameters.

COUCHDB-2031


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

Branch: refs/heads/master
Commit: 147adec8ef3763cb1821f411f393d6560aaccad2
Parents: eabece1
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Sat Jan 18 00:31:49 2014 -0500
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Sat Jan 18 00:31:49 2014 -0500

----------------------------------------------------------------------
 src/couchdb/couch_httpd_rewrite.erl | 54 +++++++++++++++-----------------
 1 file changed, 25 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/147adec8/src/couchdb/couch_httpd_rewrite.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_rewrite.erl b/src/couchdb/couch_httpd_rewrite.erl
index 1187397..4354215 100644
--- a/src/couchdb/couch_httpd_rewrite.erl
+++ b/src/couchdb/couch_httpd_rewrite.erl
@@ -143,36 +143,32 @@ handle_rewrite_req(#httpd{
             DispatchList =  [make_rule(Rule) || {Rule} <- Rules],
             Method1 = couch_util:to_binary(Method),
 
-            %% get raw path by matching url to a rule.
-            RawPath = case try_bind_path(DispatchList, Method1, 
-                    PathParts, QueryList) of
-                no_dispatch_path ->
-                    throw(not_found);
-                {NewPathParts, Bindings} ->
-                    Parts = [quote_plus(X) || X <- NewPathParts],
-
-                    % build new path, reencode query args, eventually convert
-                    % them to json
-                    Bindings1 = maybe_encode_bindings(Bindings),
-                    Path = binary_to_list(
-                        iolist_to_binary([
-                                string:join(Parts, [?SEPARATOR]),
-                                [["?", mochiweb_util:urlencode(Bindings1)] 
-                                    || Bindings1 =/= [] ]
-                            ])),
-                    
-                    % if path is relative detect it and rewrite path
-                    case mochiweb_util:safe_relative_path(Path) of
-                        undefined ->
-                            ?b2l(Prefix) ++ "/" ++ Path;
-                        P1 ->
-                            ?b2l(Prefix) ++ "/" ++ P1
-                    end
+            % get raw path by matching url to a rule. Throws not_found.
+            {NewPathParts0, Bindings0} =
+                try_bind_path(DispatchList, Method1, PathParts, QueryList),
+            NewPathParts = [quote_plus(X) || X <- NewPathParts0],
+            Bindings = maybe_encode_bindings(Bindings0),
+
+            Path0 = string:join(NewPathParts, [?SEPARATOR]),
+
+            % if path is relative detect it and rewrite path
+            Path1 = case mochiweb_util:safe_relative_path(Path0) of
+                undefined ->
+                    ?b2l(Prefix) ++ "/" ++ Path0;
+                P1 ->
+                    ?b2l(Prefix) ++ "/" ++ P1
+            end,
+
+            Path2 = normalize_path(Path1),
 
-                end,
+            Path3 = case Bindings of
+                [] ->
+                    Path2;
+                _ ->
+                    [Path2, "?", mochiweb_util:urlencode(Bindings)]
+            end,
 
-            % normalize final path (fix levels "." and "..")
-            RawPath1 = ?b2l(iolist_to_binary(normalize_path(RawPath))),
+            RawPath1 = ?b2l(iolist_to_binary(Path3)),
 
             % In order to do OAuth correctly, we have to save the
             % requested path. We use default so chained rewriting
@@ -216,7 +212,7 @@ quote_plus(X) ->
 %% @doc Try to find a rule matching current url. If none is found
 %% 404 error not_found is raised
 try_bind_path([], _Method, _PathParts, _QueryList) ->
-    no_dispatch_path;
+    throw(not_found);
 try_bind_path([Dispatch|Rest], Method, PathParts, QueryList) ->
     [{PathParts1, Method1}, RedirectPath, QueryArgs, Formats] = Dispatch,
     case bind_method(Method1, Method) of


[3/3] couchdb commit: updated refs/heads/master to 37c8459

Posted by ko...@apache.org.
Merge branch '2031-fix-qs-rewrite'

Closes COUCHDB-2031


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

Branch: refs/heads/master
Commit: 37c8459693dbf55cd4683c7e288dcc9ca8899e97
Parents: 15f4fff cb5e7f6
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Jan 22 09:32:24 2014 -0500
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Wed Jan 22 09:32:24 2014 -0500

----------------------------------------------------------------------
 share/www/script/test/rewrite.js    | 11 +++++++
 src/couchdb/couch_httpd_rewrite.erl | 54 +++++++++++++++-----------------
 2 files changed, 36 insertions(+), 29 deletions(-)
----------------------------------------------------------------------



[2/3] couchdb commit: updated refs/heads/master to 37c8459

Posted by ko...@apache.org.
Add test for path normalization with qs params

COUCHDB-2031


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

Branch: refs/heads/master
Commit: cb5e7f6a423865d45b134495888d10aa2e8ac474
Parents: 147adec
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Sat Jan 18 22:32:37 2014 -0500
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Sat Jan 18 23:17:54 2014 -0500

----------------------------------------------------------------------
 share/www/script/test/rewrite.js | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/cb5e7f6a/share/www/script/test/rewrite.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/rewrite.js b/share/www/script/test/rewrite.js
index e888032..5c56fa5 100644
--- a/share/www/script/test/rewrite.js
+++ b/share/www/script/test/rewrite.js
@@ -182,6 +182,10 @@ couchTests.rewrite = function(debug) {
             {
               "from": "/",
               "to": "_view/basicView",
+            },
+            {
+              "from": "/db/*",
+              "to": "../../*"
             }
           ],
           lists: {
@@ -402,6 +406,13 @@ couchTests.rewrite = function(debug) {
         var result = JSON.parse(xhr.responseText);
         T(typeof(result.rows[0].doc) === "object");
         
+        // COUCHDB-2031 - path normalization versus qs params
+        xhr = CouchDB.request("GET", "/"+dbName+"/_design/test/_rewrite/db/_design/test?meta=true");
+        T(xhr.status == 200, "path normalization works with qs params");
+        var result = JSON.parse(xhr.responseText);
+        T(result['_id'] == "_design/test");
+        T(typeof(result['_revs_info']) === "object");
+
         // test path relative to server
         designDoc.rewrites.push({
           "from": "uuids",