Skip to content

Commit 717ba66

Browse files
committed
Simplify mongodb removeUnsupportedChars
1 parent fa0c0d6 commit 717ba66

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/mongodb-backend.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ MongoDBBackend.prototype = {
6262
var searchParams = (this.useSingle? {_bucketname: bucket, key:key} : {key:key});
6363
var collName = (this.useSingle? aclCollectionName : bucket);
6464

65-
this.db.collection(this.prefix + removeUnsupportedChar(collName, this.useRawCollectionNames),function(err,collection){
65+
this.db.collection(this.prefix + this.removeUnsupportedChar(collName),function(err,collection){
6666
if(err instanceof Error) return cb(err);
6767
// Excluding bucket field from search result
6868
collection.findOne(searchParams, {_bucketname: 0},function(err, doc){
@@ -85,7 +85,7 @@ MongoDBBackend.prototype = {
8585
var searchParams = (this.useSingle? {_bucketname: bucket, key: { $in: keys }} : {key: { $in: keys }});
8686
var collName = (this.useSingle? aclCollectionName : bucket);
8787

88-
this.db.collection(this.prefix + removeUnsupportedChar(collName, this.useRawCollectionNames),function(err,collection){
88+
this.db.collection(this.prefix + this.removeUnsupportedChar(collName),function(err,collection){
8989
if(err instanceof Error) return cb(err);
9090
// Excluding bucket field from search result
9191
collection.find(searchParams, {_bucketname: 0}).toArray(function(err,docs){
@@ -117,7 +117,7 @@ MongoDBBackend.prototype = {
117117
var collName = (self.useSingle? aclCollectionName : bucket);
118118
transaction.push(function(cb){
119119
values = makeArray(values);
120-
self.db.collection(self.prefix + removeUnsupportedChar(collName, self.useRawCollectionNames), function(err,collection){
120+
self.db.collection(self.prefix + self.removeUnsupportedChar(collName), function(err,collection){
121121
if(err instanceof Error) return cb(err);
122122

123123
// build doc from array values
@@ -133,7 +133,7 @@ MongoDBBackend.prototype = {
133133
});
134134

135135
transaction.push(function(cb) {
136-
self.db.collection(self.prefix + removeUnsupportedChar(collName, self.useRawCollectionNames), function(err,collection){
136+
self.db.collection(self.prefix + self.removeUnsupportedChar(collName), function(err,collection){
137137
// Create index
138138
collection.ensureIndex({_bucketname: 1, key: 1}, function(err){
139139
if (err instanceof Error) {
@@ -159,7 +159,7 @@ MongoDBBackend.prototype = {
159159
var collName = (self.useSingle? aclCollectionName : bucket);
160160

161161
transaction.push(function(cb){
162-
self.db.collection(self.prefix + removeUnsupportedChar(collName, self.useRawCollectionNames),function(err,collection){
162+
self.db.collection(self.prefix + self.removeUnsupportedChar(collName),function(err,collection){
163163
if(err instanceof Error) return cb(err);
164164
collection.remove(updateParams,{safe:true},function(err){
165165
if(err instanceof Error) return cb(err);
@@ -183,7 +183,7 @@ MongoDBBackend.prototype = {
183183

184184
values = makeArray(values);
185185
transaction.push(function(cb){
186-
self.db.collection(self.prefix + removeUnsupportedChar(collName, self.useRawCollectionNames),function(err,collection){
186+
self.db.collection(self.prefix + self.removeUnsupportedChar(collName),function(err,collection){
187187
if(err instanceof Error) return cb(err);
188188

189189
// build doc from array values
@@ -197,15 +197,15 @@ MongoDBBackend.prototype = {
197197
});
198198
});
199199
});
200-
}
201-
}
200+
},
202201

203-
function removeUnsupportedChar(text, useRawCollectionNames) {
204-
if (!useRawCollectionNames && (typeof text === 'string' || text instanceof String)) {
205-
text = decodeURIComponent(text);
206-
text = text.replace(/[/\s]/g, '_'); // replaces slashes and spaces
202+
removeUnsupportedChar: function(text) {
203+
if (!this.useRawCollectionNames && (typeof text === 'string' || text instanceof String)) {
204+
text = decodeURIComponent(text);
205+
text = text.replace(/[/\s]/g, '_'); // replaces slashes and spaces
206+
}
207+
return text;
207208
}
208-
return text;
209209
}
210210

211211
function encodeText(text) {

0 commit comments

Comments
 (0)