Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 92bf9e3

Browse files
fix(odata): encode URI also for IN/NIN operators, fixes #463 (#471)
Co-authored-by: Ghislain Beaulac <[email protected]>
1 parent d978946 commit 92bf9e3

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/app/modules/angular-slickgrid/services/__tests__/grid-odata.service.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,20 @@ describe('GridOdataService', () => {
720720
expect(query).toBe(expectation);
721721
});
722722

723+
it('should return a query with a CSV string when the filter operator is IN ', () => {
724+
const expectation = `$top=10&$filter=(Gender eq 'female' or Gender eq 'ma%2Fle')`;
725+
const mockColumn = { id: 'gender', field: 'gender' } as Column;
726+
const mockColumnFilters = {
727+
gender: { columnId: 'gender', columnDef: mockColumn, searchTerms: ['female', 'ma/le'], operator: 'IN' },
728+
} as ColumnFilters;
729+
730+
service.init(serviceOptions, paginationOptions, gridStub);
731+
service.updateFilters(mockColumnFilters, false);
732+
const query = service.buildQuery();
733+
734+
expect(query).toBe(expectation);
735+
});
736+
723737
it('should return a query with a CSV string when the filter operator is IN for numeric column type', () => {
724738
const expectation = `$top=10&$filter=(Id eq 100 or Id eq 101)`;
725739
const mockColumn = { id: 'id', field: 'id', type: FieldType.number } as Column;
@@ -748,6 +762,20 @@ describe('GridOdataService', () => {
748762
expect(query).toBe(expectation);
749763
});
750764

765+
it('should return a query with a CSV string when the filter operator is NOT_IN', () => {
766+
const expectation = `$top=10&$filter=(Gender ne 'female' and Gender ne 'ma%2Fle')`;
767+
const mockColumn = { id: 'gender', field: 'gender' } as Column;
768+
const mockColumnFilters = {
769+
gender: { columnId: 'gender', columnDef: mockColumn, searchTerms: ['female', 'ma/le'], operator: OperatorType.notIn },
770+
} as ColumnFilters;
771+
772+
service.init(serviceOptions, paginationOptions, gridStub);
773+
service.updateFilters(mockColumnFilters, false);
774+
const query = service.buildQuery();
775+
776+
expect(query).toBe(expectation);
777+
});
778+
751779
it('should return a query with a CSV string and use the operator from the Column Definition Operator when provided', () => {
752780
const expectation = `$top=10&$filter=(Gender ne 'female' and Gender ne 'male')`;
753781
const mockColumn = { id: 'gender', field: 'gender', filter: { operator: OperatorType.notIn } } as Column;

src/app/modules/angular-slickgrid/services/grid-odata.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export class GridOdataService implements BackendService {
328328
// example:: (Stage eq "Expired" or Stage eq "Renewal")
329329
for (let j = 0, lnj = searchTerms.length; j < lnj; j++) {
330330
if (fieldType === FieldType.string) {
331-
const searchVal = searchTerms[j].replace(`'`, `''`);
331+
const searchVal = encodeURIComponent(searchTerms[j].replace(`'`, `''`));
332332
tmpSearchTerms.push(`${fieldName} eq '${searchVal}'`);
333333
} else {
334334
// Single quote escape is not needed for non string type
@@ -342,7 +342,7 @@ export class GridOdataService implements BackendService {
342342
} else {
343343
// example:: (Stage ne "Expired" and Stage ne "Renewal")
344344
for (let k = 0, lnk = searchTerms.length; k < lnk; k++) {
345-
const searchVal = searchTerms[k].replace(`'`, `''`);
345+
const searchVal = encodeURIComponent(searchTerms[k].replace(`'`, `''`));
346346
tmpSearchTerms.push(`${fieldName} ne '${searchVal}'`);
347347
}
348348
searchBy = tmpSearchTerms.join(' and ');

0 commit comments

Comments
 (0)