- diff --git a/lib/net_cordia/cherry_filter_util.rb b/lib/net_cordia/cherry_filter_util.rb
- index 1932ee7..ef162b8 100644
- --- a/lib/net_cordia/cherry_filter_util.rb
- +++ b/lib/net_cordia/cherry_filter_util.rb
- @@ -32,7 +32,7 @@ module NetCordia
- end
- return x
- end
- - return '' if filter['values'].blank?
- + return '' if filter['values'].blank?
- if filter['operatorId']
- # we are a leaf, do the right thing
- statement = CONVERT_IT[filter['operatorId']]
- @@ -45,6 +45,10 @@ module NetCordia
- rtn = rtn.gsub("like", "rlike")
- rtn = rtn.gsub("%", ".*")
- else
- + if statement[0] =~ /.*like.*/
- + # now we need to deal with wildcards: % and _
- + value = value.gsub('%','\%').gsub('_','\_')
- + end
- values.push(value)
- end
- elsif statement[1] == 2
- diff --git a/spec/lib/cherry_filter_util_spec.rb b/spec/lib/cherry_filter_util_spec.rb
- new file mode 100644
- index 0000000..f97a4cd
- --- /dev/null
- +++ b/spec/lib/cherry_filter_util_spec.rb
- @@ -0,0 +1,105 @@
- +require File.dirname(__FILE__) + '/../spec_helper'
- +
- +describe NetCordia::CherryFilterUtil do
- + def escape_test(condition,value)
- + filter = {
- + "fieldId"=>'test',
- + "operatorId"=>condition,
- + "values"=>[{
- + "label"=>value,
- + "value"=>value
- + }]
- + }.to_json
- +
- + NetCordia::CherryFilterUtil.sql_condition_from_filter(filter)[1].should == "\\#{value}"
- + end
- +
- + def nonescape_test(condition,value)
- + filter = {
- + "fieldId"=>'test',
- + "operatorId"=>condition,
- + "values"=>[{
- + "label"=>value,
- + "value"=>value
- + }]
- + }.to_json
- +
- + RAILS_DEFAULT_LOGGER.debug NetCordia::CherryFilterUtil.sql_condition_from_filter(filter)#[1].should == value
- + end
- +
- + it 'should escape "%" for STRING_CONTAINS' do
- + escape_test('STRING_CONTAINS','%')
- + end
- + it 'should escape "%" for STRING_DOESNT_CONTAIN' do
- + escape_test('STRING_DOESNT_CONTAIN','%')
- + end
- + it 'should escape "%" for STRING_STARTS_WITH' do
- + escape_test('STRING_STARTS_WITH','%')
- + end
- + it 'should escape "%" for STRING_ENDS_WITH' do
- + escape_test('STRING_ENDS_WITH','%')
- + end
- +
- + it 'should escape "_" for STRING_CONTAINS' do
- + escape_test('STRING_CONTAINS','_')
- + end
- + it 'should escape "_" for STRING_DOESNT_CONTAIN' do
- + escape_test('STRING_DOESNT_CONTAIN','_')
- + end
- + it 'should escape "_" for STRING_STARTS_WITH' do
- + escape_test('STRING_STARTS_WITH','_')
- + end
- + it 'should escape "_" for STRING_ENDS_WITH' do
- + escape_test('STRING_ENDS_WITH','_')
- + end
- +
- +
- + it 'should not escape "%" for STRING_EQUAL' do
- + nonescape_test('STRING_EQUAL','%')
- + end
- + it 'should not escape "%" for STRING_DIFFERENT' do
- + nonescape_test('STRING_DIFFERENT','%')
- + end
- + it 'should not escape "%" for STRING_IN_LIST' do
- + nonescape_test('STRING_IN_LIST','%')
- + end
- + it 'should not escape "%" for STRING_NOT_IN_LIST' do
- + nonescape_test('STRING_NOT_IN_LIST','%')
- + end
- + it 'should not escape "%" for NUMBER_EQUAL' do
- + nonescape_test('NUMBER_EQUAL','%')
- + end
- + it 'should not escape "%" for NUMBER_NOT_EQUAL' do
- + nonescape_test('NUMBER_NOT_EQUAL','%')
- + end
- + it 'should not escape "%" for NUMBER_GREATER' do
- + nonescape_test('NUMBER_GREATER','%')
- + end
- + it 'should not escape "%" for NUMBER_GREATER_OR_EQUAL' do
- + nonescape_test('NUMBER_GREATER_OR_EQUAL','%')
- + end
- + it 'should not escape "%" for NUMBER_LESS' do
- + nonescape_test('NUMBER_LESS','%')
- + end
- + it 'should not escape "%" for NUMBER_LESS_OR_EQUAL' do
- + nonescape_test('NUMBER_LESS_OR_EQUAL','%')
- + end
- + it 'should not escape "%" for DATE_EQUAL' do
- + nonescape_test('DATE_EQUAL','%')
- + end
- + it 'should not escape "%" for DATE_GREATER' do
- + nonescape_test('DATE_GREATER','%')
- + end
- + it 'should not escape "%" for DATE_GREATER_OR_EQUAL' do
- + nonescape_test('DATE_GREATER_OR_EQUAL','%')
- + end
- + it 'should not escape "%" for DATE_LESS' do
- + nonescape_test('DATE_LESS','%')
- + end
- + it 'should not escape "%" for DATE_LESS_OR_EQUAL' do
- + nonescape_test('DATE_LESS_OR_EQUAL','%')
- + end
- + it 'should not escape "%" for DATE_RANGE' do
- + nonescape_test('DATE_RANGE','%')
- + end
- +end
- \ No newline at end of file