Skip to content

Commit 3bd8f6e

Browse files
fix: Ensure property filter prefers case-sensitive match (#575)
1 parent deb99d9 commit 3bd8f6e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/property-filter/__tests__/utils.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ describe('matchFilteringProperty', () => {
4242
const property = matchFilteringProperty(filteringProperties, ' Averange latency');
4343
expect(property).toBe(null);
4444
});
45+
test('should prefer an exact match to non-exact', () => {
46+
const properties: FilteringProperty[] = [
47+
{ key: 'Test', propertyLabel: 'Test', groupValuesLabel: '' },
48+
{ key: 'test', propertyLabel: 'test', groupValuesLabel: '' },
49+
];
50+
const property = matchFilteringProperty(properties, 'test');
51+
expect(property).toBe(properties[1]);
52+
});
4553
});
4654

4755
describe('matchOperator', () => {

src/property-filter/utils.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ export function matchFilteringProperty(
88
filteringProperties: readonly FilteringProperty[],
99
filteringText: string
1010
): null | FilteringProperty {
11-
filteringText = filteringText.toLowerCase();
12-
1311
let maxLength = 0;
1412
let matchedProperty: null | FilteringProperty = null;
1513

1614
for (const property of filteringProperties) {
17-
if (property.propertyLabel.length > maxLength && startsWith(filteringText, property.propertyLabel.toLowerCase())) {
15+
if (property.propertyLabel === filteringText) {
16+
matchedProperty = property;
17+
break;
18+
}
19+
if (
20+
property.propertyLabel.length > maxLength &&
21+
startsWith(filteringText.toLowerCase(), property.propertyLabel.toLowerCase())
22+
) {
1823
maxLength = property.propertyLabel.length;
1924
matchedProperty = property;
2025
}

0 commit comments

Comments
 (0)