Skip to content

Commit

Permalink
fix(odata): no quote escape required for IN operator w/non-string col…
Browse files Browse the repository at this point in the history
…umn (#262)
  • Loading branch information
ghiscoding committed Nov 22, 2019
1 parent 5b08b6e commit 8027922
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,20 @@ describe('GridOdataService', () => {
expect(query).toBe(expectation);
});

it('should return a query with a CSV string when the filter operator is IN for numeric column type', () => {
const expectation = `$top=10&$filter=(Id eq 100 or Id eq 101)`;
const mockColumn = { id: 'id', field: 'id', type: FieldType.number } as Column;
const mockColumnFilters = {
gender: { columnId: 'id', columnDef: mockColumn, searchTerms: [100, 101], operator: 'IN' },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(query).toBe(expectation);
});

it('should return a query with a CSV string when the filter operator is NOT_IN', () => {
const expectation = `$top=10&$filter=(Gender ne 'female' and Gender ne 'male')`;
const mockColumn = { id: 'gender', field: 'gender' } as Column;
Expand Down
9 changes: 7 additions & 2 deletions src/aurelia-slickgrid/services/grid-odata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,13 @@ export class GridOdataService implements BackendService {
if (operator === 'IN') {
// example:: (Stage eq "Expired" or Stage eq "Renewal")
for (let j = 0, lnj = searchTerms.length; j < lnj; j++) {
const searchVal = searchTerms[j].replace(`'`, `''`);
tmpSearchTerms.push(`${fieldName} eq '${searchVal}'`);
if (fieldType === FieldType.string) {
const searchVal = searchTerms[j].replace(`'`, `''`);
tmpSearchTerms.push(`${fieldName} eq '${searchVal}'`);
} else {
// Single quote escape is not needed for non string type
tmpSearchTerms.push(`${fieldName} eq ${searchTerms[j]}`);
}
}
searchBy = tmpSearchTerms.join(' or ');
if (!(typeof searchBy === 'string' && searchBy[0] === '(' && searchBy.slice(-1) === ')')) {
Expand Down

0 comments on commit 8027922

Please sign in to comment.