Skip to content

Commit 3cbc7fc

Browse files
Ryan Quinnlbdremy
Ryan Quinn
authored andcommitted
FIX: Remove format.escapeAndEncode method, and replace with encodeURIComponent where appropriate
1 parent 7c0b82b commit 3cbc7fc

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

lib/query.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ Query.prototype.rangeFilter = function(options){
201201
var filters = options.map(function(option){
202202
var key = option.field;
203203
var filter = {};
204-
filter[key] = '[' + format.escapeAndEncode(option.start) + '%20TO%20' + format.escapeAndEncode(option.end) + ']';
204+
filter[key] = '[' + encodeURIComponent(option.start) + '%20TO%20' + encodeURIComponent(option.end) + ']';
205205
return format.stringify(filter, '',':');
206206
});
207207
parameter += filters.join('%20AND%20');
208208
parameter += ")";
209209
}else{
210210
var key = options.field;
211211
var filter = {};
212-
filter[key] = '[' + format.escapeAndEncode(options.start) + '%20TO%20' + format.escapeAndEncode(options.end) + ']';
212+
filter[key] = '[' + encodeURIComponent(options.start) + '%20TO%20' + encodeURIComponent(options.end) + ']';
213213
parameter += format.stringify(filter, '',':');
214214
}
215215
this.parameters.push(parameter);
@@ -234,7 +234,7 @@ Query.prototype.matchFilter = function(field,value){
234234
var self = this;
235235
value = format.dateISOify(value);
236236
var parameter = 'fq=';
237-
parameter += field + ':' + format.escapeAndEncode(value);
237+
parameter += field + ':' + encodeURIComponent(value);
238238
this.parameters.push(parameter);
239239
return self;
240240
}
@@ -341,7 +341,7 @@ Query.prototype.group = function(options){
341341
this.parameters.push('group.sort=' + encodeURIComponent(options.sort));
342342
}
343343
if( options.format ){
344-
this.parameters.push('group.format=' + format.escapeAndEncode(options.format));
344+
this.parameters.push('group.format=' + encodeURIComponent(options.format));
345345
}
346346
if( options.main !== undefined){
347347
this.parameters.push('group.main=' + options.main);
@@ -395,10 +395,10 @@ Query.prototype.facet = function(options){
395395
}
396396
}
397397
if(options.prefix){
398-
this.parameters.push('facet.prefix=' + format.escapeAndEncode(options.prefix))
398+
this.parameters.push('facet.prefix=' + encodeURIComponent(options.prefix))
399399
}
400400
if(options.sort){
401-
this.parameters.push('facet.sort=' + format.escapeAndEncode(options.sort))
401+
this.parameters.push('facet.sort=' + encodeURIComponent(options.sort))
402402
}
403403
if(options.limit !== undefined){
404404
this.parameters.push('facet.limit=' + options.limit);
@@ -447,7 +447,7 @@ Query.prototype.mlt = function(options){
447447
}
448448
if(options.fl){
449449
if(options.fl instanceof Array) options.fl = options.fl.join(',');
450-
this.parameters.push('mlt.fl=' + format.escapeAndEncode(options.fl))
450+
this.parameters.push('mlt.fl=' + encodeURIComponent(options.fl))
451451
}
452452
if(options.count !== undefined){
453453
this.parameters.push('mlt.count=' + options.count)
@@ -477,7 +477,7 @@ Query.prototype.mlt = function(options){
477477
if( typeof options.qf === 'object'){
478478
var parameter = querystring.stringify(options.qf, '%20' , '^');;
479479
}else{
480-
var parameter = format.escapeAndEncode(options.qf);
480+
var parameter = encodeURIComponent(options.qf);
481481
}
482482
this.parameters.push('mlt.qf=' + parameter);
483483
}

lib/utils/format.js

-18
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,3 @@ function escapeSpecialChars(s){
132132
return '\\' + match;
133133
});
134134
}
135-
136-
/**
137-
* Expose `escapeAndEncode`
138-
*/
139-
140-
exports.escapeAndEncode = escapeAndEncode;
141-
142-
/**
143-
* Escape with `escapeSpecialChars` and encode with `encodeURIComponent`
144-
* @param {String} s - string to escape and encode
145-
*
146-
* @return {String}
147-
* @api private
148-
*/
149-
150-
function escapeAndEncode(s){
151-
return encodeURIComponent(escapeSpecialChars(s.toString()));
152-
}

test/facet-query-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Client#createQuery()',function(){
7777
"facet.offset": "5",
7878
"facet.prefix": "prefix",
7979
"facet.query": "query",
80-
"facet.sort": "field\\ desc"
80+
"facet.sort": "field desc"
8181
}
8282
);
8383
assert.equal(data.debug.QParser,'LuceneQParser');
@@ -141,7 +141,7 @@ describe('Client#createQuery()',function(){
141141
"facet.offset": "5",
142142
"facet.prefix": "prefix",
143143
"facet.query": "query",
144-
"facet.sort": "field\\ desc"
144+
"facet.sort": "field desc"
145145
}
146146
);
147147
assert.equal(data.debug.QParser,'LuceneQParser');

0 commit comments

Comments
 (0)