Skip to content
Permalink
Browse files

FIX: Remove format.escapeAndEncode method, and replace with encodeURI…

…Component where appropriate
  • Loading branch information...
Ryan Quinn authored and lbdremy committed Dec 4, 2014
1 parent 7c0b82b commit 3cbc7fc6cf631f019a4626913c0a4b616092133b
Showing with 10 additions and 28 deletions.
  1. +8 −8 lib/query.js
  2. +0 −18 lib/utils/format.js
  3. +2 −2 test/facet-query-test.js
@@ -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);
@@ -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;
}
@@ -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);
@@ -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);
@@ -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)
@@ -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);
}
@@ -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()));
}
@@ -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');
@@ -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');

0 comments on commit 3cbc7fc

Please sign in to comment.
You can’t perform that action at this time.