diff --git a/src/app/modules/angular-slickgrid/services/__tests__/grid-odata.service.spec.ts b/src/app/modules/angular-slickgrid/services/__tests__/grid-odata.service.spec.ts index 3492e3a1f..e66d9279e 100644 --- a/src/app/modules/angular-slickgrid/services/__tests__/grid-odata.service.spec.ts +++ b/src/app/modules/angular-slickgrid/services/__tests__/grid-odata.service.spec.ts @@ -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 ', () => { + const expectation = `$top=10&$filter=(Gender eq 'female' or Gender eq 'ma%2Fle')`; + const mockColumn = { id: 'gender', field: 'gender' } as Column; + const mockColumnFilters = { + gender: { columnId: 'gender', columnDef: mockColumn, searchTerms: ['female', 'ma/le'], 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 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; @@ -748,6 +762,20 @@ describe('GridOdataService', () => { 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 'ma%2Fle')`; + const mockColumn = { id: 'gender', field: 'gender' } as Column; + const mockColumnFilters = { + gender: { columnId: 'gender', columnDef: mockColumn, searchTerms: ['female', 'ma/le'], operator: OperatorType.notIn }, + } 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 and use the operator from the Column Definition Operator when provided', () => { const expectation = `$top=10&$filter=(Gender ne 'female' and Gender ne 'male')`; const mockColumn = { id: 'gender', field: 'gender', filter: { operator: OperatorType.notIn } } as Column; diff --git a/src/app/modules/angular-slickgrid/services/grid-odata.service.ts b/src/app/modules/angular-slickgrid/services/grid-odata.service.ts index 009f18070..6814a0ec7 100644 --- a/src/app/modules/angular-slickgrid/services/grid-odata.service.ts +++ b/src/app/modules/angular-slickgrid/services/grid-odata.service.ts @@ -328,7 +328,7 @@ export class GridOdataService implements BackendService { // example:: (Stage eq "Expired" or Stage eq "Renewal") for (let j = 0, lnj = searchTerms.length; j < lnj; j++) { if (fieldType === FieldType.string) { - const searchVal = searchTerms[j].replace(`'`, `''`); + const searchVal = encodeURIComponent(searchTerms[j].replace(`'`, `''`)); tmpSearchTerms.push(`${fieldName} eq '${searchVal}'`); } else { // Single quote escape is not needed for non string type @@ -342,7 +342,7 @@ export class GridOdataService implements BackendService { } else { // example:: (Stage ne "Expired" and Stage ne "Renewal") for (let k = 0, lnk = searchTerms.length; k < lnk; k++) { - const searchVal = searchTerms[k].replace(`'`, `''`); + const searchVal = encodeURIComponent(searchTerms[k].replace(`'`, `''`)); tmpSearchTerms.push(`${fieldName} ne '${searchVal}'`); } searchBy = tmpSearchTerms.join(' and ');