Skip to content

Commit 889586f

Browse files
feat: do not encode _search filter
Ref.: ONE-5334
1 parent 5088218 commit 889586f

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/helper.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-restricted-syntax */
12
import * as superagent from 'superagent';
23
import * as validator from 'json-schema-remote';
34

@@ -607,7 +608,6 @@ export function optionsToQuery(
607608
throw new Error(`filterOptions must be an object, is: ${typeof options}`);
608609
}
609610

610-
// Optimize: Use for...of loop instead of forEach for better performance
611611
for (const key of Object.keys(options)) {
612612
const value = options[key];
613613
if (value !== undefined) {
@@ -626,9 +626,9 @@ export function optionsToQuery(
626626
}
627627
} else if (key === '_levels') {
628628
if (!Number.isInteger(<number>value)) {
629-
throw new Error('_levels must be integer, is ' + typeof value);
629+
throw new Error(`_levels must be integer, is ${typeof value}`);
630630
}
631-
if (value > 1 && value <= 5) {
631+
if (Number(value) > 1 && Number(value) <= 5) {
632632
out[key] = value;
633633
}
634634
} else if (key === '_fields') {
@@ -648,7 +648,7 @@ export function optionsToQuery(
648648
throw new Error('_search must be a string');
649649
}
650650
out[key] = value;
651-
if (encode) {
651+
if (encode && key !== '_search') {
652652
out[key] = encodeURIComponent(<string>out[key]);
653653
}
654654
} else if (typeof value === 'string') {
@@ -664,7 +664,6 @@ export function optionsToQuery(
664664
} else if (value instanceof Date) {
665665
out[key] = (<Date>value).toISOString();
666666
} else if (typeof value === 'object') {
667-
// Optimize: Use for...of loop instead of forEach for better performance
668667
for (const searchKey of Object.keys(value)) {
669668
switch (searchKey) {
670669
case 'exact':

test/Core.test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,6 @@ describe('optionsToQuery', () => {
805805
};
806806
helper.optionsToQuery(obj, null, false, false, true).should.have.property('_search', 'my search term');
807807
});
808-
it('should have _search filter encoded', () => {
809-
const obj = {
810-
_search: 'my search term',
811-
};
812-
helper.optionsToQuery(obj, null, true, false, true).should.have.property('_search', 'my%20search%20term');
813-
});
814808
it('should throw on invalid _search', () => {
815809
const throws = () => {
816810
helper.optionsToQuery({ _search: 123 }, null, false, false, true);

0 commit comments

Comments
 (0)