summaryrefslogtreecommitdiff
path: root/test/elixir
diff options
context:
space:
mode:
authorncshaw <ncshaw@ibm.com>2021-08-07 06:16:17 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2021-08-10 14:36:10 -0400
commitff1e656a34c9c09ec2a1840753286043ce072871 (patch)
tree3e3a93da37b38c0601bc1a0ecd3617a4001e5c83 /test/elixir
parentcc05c03866d88bdaac6036a4cdcd55c92833302f (diff)
downloadcouchdb-ff1e656a34c9c09ec2a1840753286043ce072871.tar.gz
Improve handling of + in urls 3.x
Diffstat (limited to 'test/elixir')
-rw-r--r--test/elixir/test/basics_test.exs56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/elixir/test/basics_test.exs b/test/elixir/test/basics_test.exs
index dbdc7d193..e6fb20938 100644
--- a/test/elixir/test/basics_test.exs
+++ b/test/elixir/test/basics_test.exs
@@ -58,6 +58,62 @@ defmodule BasicsTest do
assert context[:db_name] in Couch.get("/_all_dbs").body, "Db name in _all_dbs"
end
+ test "Database name with '+' should encode to '+'", _context do
+ set_config({"chttpd", "decode_plus_to_space", "false"})
+
+ random_number = :rand.uniform(16_000_000)
+ db_name = "random+test+db+#{random_number}"
+ resp = Couch.put("/#{db_name}")
+
+ assert resp.status_code == 201
+ assert resp.body["ok"] == true
+
+ resp = Couch.get("/#{db_name}")
+
+ assert resp.status_code == 200
+ assert resp.body["db_name"] == db_name
+ end
+
+ test "Database name with '%2B' should encode to '+'", _context do
+ set_config({"chttpd", "decode_plus_to_space", "true"})
+
+ random_number = :rand.uniform(16_000_000)
+ db_name = "random%2Btest%2Bdb2%2B#{random_number}"
+ resp = Couch.put("/#{db_name}")
+
+ assert resp.status_code == 201
+ assert resp.body["ok"] == true
+
+ resp = Couch.get("/#{db_name}")
+
+ assert resp.status_code == 200
+ assert resp.body["db_name"] == "random+test+db2+#{random_number}"
+ end
+
+ @tag :with_db
+ test "'+' in document name should encode to '+'", context do
+ set_config({"chttpd", "decode_plus_to_space", "false"})
+
+ db_name = context[:db_name]
+ doc_id = "test+doc"
+ resp = Couch.put("/#{db_name}/#{doc_id}", body: %{})
+
+ assert resp.status_code == 201
+ assert resp.body["id"] == "test+doc"
+ end
+
+ @tag :with_db
+ test "'+' in document name should encode to space", context do
+ set_config({"chttpd", "decode_plus_to_space", "true"})
+
+ db_name = context[:db_name]
+ doc_id = "test+doc+2"
+ resp = Couch.put("/#{db_name}/#{doc_id}", body: %{})
+
+ assert resp.status_code == 201
+ assert resp.body["id"] == "test doc 2"
+ end
+
@tag :with_db
test "Empty database should have zero docs", context do
assert Couch.get("/#{context[:db_name]}").body["doc_count"] == 0,