Skip to content

Commit

Permalink
FIX: Remove format.escapeAndEncode method, and replace with encodeURI…
Browse files Browse the repository at this point in the history
…Component where appropriate
  • Loading branch information
Ryan Quinn authored and lbdremy committed Dec 7, 2014
1 parent 7c0b82b commit 3cbc7fc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
16 changes: 8 additions & 8 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ Query.prototype.rangeFilter = function(options){
var filters = options.map(function(option){
var key = option.field;
var filter = {};
filter[key] = '[' + format.escapeAndEncode(option.start) + '%20TO%20' + format.escapeAndEncode(option.end) + ']';
filter[key] = '[' + encodeURIComponent(option.start) + '%20TO%20' + encodeURIComponent(option.end) + ']';
return format.stringify(filter, '',':');
});
parameter += filters.join('%20AND%20');
parameter += ")";
}else{
var key = options.field;
var filter = {};
filter[key] = '[' + format.escapeAndEncode(options.start) + '%20TO%20' + format.escapeAndEncode(options.end) + ']';
filter[key] = '[' + encodeURIComponent(options.start) + '%20TO%20' + encodeURIComponent(options.end) + ']';
parameter += format.stringify(filter, '',':');
}
this.parameters.push(parameter);
Expand All @@ -234,7 +234,7 @@ Query.prototype.matchFilter = function(field,value){
var self = this;
value = format.dateISOify(value);
var parameter = 'fq=';
parameter += field + ':' + format.escapeAndEncode(value);
parameter += field + ':' + encodeURIComponent(value);
this.parameters.push(parameter);
return self;
}
Expand Down Expand Up @@ -341,7 +341,7 @@ Query.prototype.group = function(options){
this.parameters.push('group.sort=' + encodeURIComponent(options.sort));
}
if( options.format ){
this.parameters.push('group.format=' + format.escapeAndEncode(options.format));
this.parameters.push('group.format=' + encodeURIComponent(options.format));
}
if( options.main !== undefined){
this.parameters.push('group.main=' + options.main);
Expand Down Expand Up @@ -395,10 +395,10 @@ Query.prototype.facet = function(options){
}
}
if(options.prefix){
this.parameters.push('facet.prefix=' + format.escapeAndEncode(options.prefix))
this.parameters.push('facet.prefix=' + encodeURIComponent(options.prefix))
}
if(options.sort){
this.parameters.push('facet.sort=' + format.escapeAndEncode(options.sort))
this.parameters.push('facet.sort=' + encodeURIComponent(options.sort))
}
if(options.limit !== undefined){
this.parameters.push('facet.limit=' + options.limit);
Expand Down Expand Up @@ -447,7 +447,7 @@ Query.prototype.mlt = function(options){
}
if(options.fl){
if(options.fl instanceof Array) options.fl = options.fl.join(',');
this.parameters.push('mlt.fl=' + format.escapeAndEncode(options.fl))
this.parameters.push('mlt.fl=' + encodeURIComponent(options.fl))
}
if(options.count !== undefined){
this.parameters.push('mlt.count=' + options.count)
Expand Down Expand Up @@ -477,7 +477,7 @@ Query.prototype.mlt = function(options){
if( typeof options.qf === 'object'){
var parameter = querystring.stringify(options.qf, '%20' , '^');;
}else{
var parameter = format.escapeAndEncode(options.qf);
var parameter = encodeURIComponent(options.qf);
}
this.parameters.push('mlt.qf=' + parameter);
}
Expand Down
18 changes: 0 additions & 18 deletions lib/utils/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,3 @@ function escapeSpecialChars(s){
return '\\' + match;
});
}

/**
* Expose `escapeAndEncode`
*/

exports.escapeAndEncode = escapeAndEncode;

/**
* Escape with `escapeSpecialChars` and encode with `encodeURIComponent`
* @param {String} s - string to escape and encode
*
* @return {String}
* @api private
*/

function escapeAndEncode(s){
return encodeURIComponent(escapeSpecialChars(s.toString()));
}
4 changes: 2 additions & 2 deletions test/facet-query-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Client#createQuery()',function(){
"facet.offset": "5",
"facet.prefix": "prefix",
"facet.query": "query",
"facet.sort": "field\\ desc"
"facet.sort": "field desc"
}
);
assert.equal(data.debug.QParser,'LuceneQParser');
Expand Down Expand Up @@ -141,7 +141,7 @@ describe('Client#createQuery()',function(){
"facet.offset": "5",
"facet.prefix": "prefix",
"facet.query": "query",
"facet.sort": "field\\ desc"
"facet.sort": "field desc"
}
);
assert.equal(data.debug.QParser,'LuceneQParser');
Expand Down

0 comments on commit 3cbc7fc

Please sign in to comment.