Skip to content

Commit

Permalink
Fix filtering issues for string in different locales (T1242756) (#28008)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodDayForSurf authored Sep 6, 2024
1 parent 8244a12 commit ad19680
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/devextreme/js/core/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ function combineGetters(getters) {
};
}

function toLowerCase(value, options) {
return options?.locale ? value.toLocaleLowerCase(options.locale) : value.toLowerCase();
}

function toUpperCase(value, options) {
return options?.locale ? value.toLocaleUpperCase(options.locale) : value.toUpperCase();
}

const ensurePropValueDefined = function(obj, propName, value, options) {
if(isDefined(value)) {
return value;
Expand Down Expand Up @@ -198,7 +206,10 @@ export const toComparable = function(value, caseSensitive, options = {}) {
value = value.normalize('NFD').replace(REMOVE_DIACRITICAL_MARKS_REGEXP, '');
}

return options?.locale ? value.toLocaleLowerCase(options.locale) : value.toLowerCase();
const locale = options?.locale?.toLowerCase();
const useUpperCase = locale && !!['hy', 'el'].find((code) => locale === code || locale.startsWith(`${code}-`));

return (useUpperCase ? toUpperCase : toLowerCase)(value, options);
}

return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,69 @@ QUnit.test('filter with collatorOptions.sensitivity set to "base"', function(ass
assert.false(containsUnwantedValue);
});

QUnit.test('filtering use correct case insensitivity equal', function(assert) {
const input = [{ ID: 1, Name: 'AΙΤΗΣ' }, { ID: 2, Name: 'aιτης' }, { ID: 3, Name: 'abcde' }];

const array = QUERY(input, {
langParams: {
locale: 'el-GR'
}
}).filter(['Name', '=', 'AΙΤΗΣ']).toArray();

assert.equal(array.length, 2);

const containsUnwantedValue = array.some(item => item.ID === 3);
assert.false(containsUnwantedValue);
});

QUnit.test('filtering use correct case insensitivity search', function(assert) {
const input = [
{ ID: 1, Name: 'AΙΤΗΣ' },
{ ID: 2, Name: 'aιτης' },
{ ID: 3, Name: 'aιτησa' },
{ ID: 4, Name: 'AΙΤΗΣΗ' },
{ ID: 5, Name: 'ΑBΤΗΣΗ' },
{ ID: 6, Name: 'BΑΙΤΗΣΗ' },
{ ID: 7, Name: 'baιτησa' },
];

const query = QUERY(input, {
langParams: {
locale: 'el-GR'
}
});

const arrayStartsWith = query.filter(['Name', 'startswith', 'AΙΤΗΣ']).toArray();

const arrayEndsWith = query.filter(['Name', 'endswith', 'ΙΤΗΣ']).toArray();

const arrayContains = query.filter(['Name', 'contains', 'ΙΤΗΣ']).toArray();

assert.equal(arrayStartsWith.length, 4);
assert.equal(arrayEndsWith.length, 2);
assert.equal(arrayContains.length, 6);

const containsUnwantedValue = arrayStartsWith.some(item => [5, 6, 7].includes(item.ID))
|| arrayEndsWith.some(item => [5, 4, 3, 6, 7].includes(item.ID))
|| arrayContains.some(item => [5].includes(item.ID));
assert.false(containsUnwantedValue);
});

QUnit.test('filtering use correct case insensitivity search for Armenian locale', function(assert) {
const input = [
{ ID: 1, Name: 'ԵՐԵՒԱՆ' },
{ ID: 2, Name: 'Երևան' },
];

const arrayStartsWith = QUERY(input, {
langParams: {
locale: 'hy'
}
}).filter(['Name', 'startswith', 'Երև']).toArray();

assert.equal(arrayStartsWith.length, 2);
});

QUnit.test('missing operation means equal', function(assert) {
assert.expect(1);

Expand Down

0 comments on commit ad19680

Please sign in to comment.