Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added uri encoding in the relax function being applied to db property.

added a test for this.
not really 100% sure it works, but all tests are passing.
  • Loading branch information...
commit c040f9d876664dbdaade7ba947ab0e00caf47527 1 parent c2ee0d0
@boxxxie authored
View
3  nano.js
@@ -50,6 +50,7 @@ module.exports = exports = nano = function database_module(cfg) {
, db
, auth
, port
+ , encode_db_name = encodeURIComponent
;
/***************************************************************************
@@ -124,7 +125,7 @@ module.exports = exports = nano = function database_module(cfg) {
}
if(opts.db) {
- req.uri = u.resolve(req.uri, opts.db);
+ req.uri = u.resolve(req.uri, encode_db_name(opts.db));
}
if (opts.headers) {
View
8 tests/db/create.js
@@ -7,17 +7,19 @@ var specify = require('specify')
var mock = nock(helpers.couch, "db/create");
+var db_name = "db_create";
+
specify("db_create:test", timeout, function (assert) {
- nano.db.create("db_create", function (err) {
+ nano.db.create(db_name, function (err) {
assert.equal(err, undefined, "Failed to create database");
});
});
specify("db_create:teardown", timeout, function (assert) {
- nano.db.destroy("db_create", function (err) {
+ nano.db.destroy(db_name, function (err) {
assert.equal(err, undefined, "Failed to destroy database");
assert.ok(mock.isDone(), "Some mocks didn't run");
});
});
-specify.run(process.argv.slice(2));
+specify.run(process.argv.slice(2));
View
25 tests/db/encodeDbName.js
@@ -0,0 +1,25 @@
+var specify = require('specify')
+ , helpers = require('../helpers')
+ , timeout = helpers.timeout
+ , nano = helpers.nano
+ , nock = helpers.nock
+ ;
+
+var mock = nock(helpers.couch, "db/encodeDbName");
+
+var db_name = "az09_$()+-/";
+
+specify("db_create:test", timeout, function (assert) {
+ nano.db.create(db_name, function (err) {
+ assert.equal(err, undefined, "Failed to create database");
+ });
+});
+
+specify("db_create:teardown", timeout, function (assert) {
+ nano.db.destroy(db_name, function (err) {
+ assert.equal(err, undefined, "Failed to destroy database");
+ assert.ok(mock.isDone(), "Some mocks didn't run");
+ });
+});
+
+specify.run(process.argv.slice(2));
View
11 tests/fixtures/db/encodeDbName.json
@@ -0,0 +1,11 @@
+[
+ { "method" : "put"
+ , "path" : "/az09_%24()%2B-%2F"
+ , "status" : 201
+ , "response" : "{ \"ok\": true }"
+ }
+, { "method" : "delete"
+ , "path" : "/az09_%24()%2B-%2F"
+ , "response" : "{ \"ok\": true }"
+ }
+]
Please sign in to comment.
Something went wrong with that request. Please try again.