Skip to content

Commit 893bcb4

Browse files
committed
Fix bug in filter descriptions for not() with exact + partial submatches
If you entered 'not(header' it matches header/headers, and it always selected 'headers' for the description as the longest option, even though it's clearly the worst. We now prioritise fuller matches significantly (mildly hacky approach, but should be fine in practice I think).
1 parent 4afb185 commit 893bcb4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/model/filters/search-filters.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,11 @@ class NotFilter extends Filter {
14021402
match: matchSyntax(filter.filterSyntax, innerValue, 0)
14031403
})).filter(({ match }) => (match?.partiallyConsumed || 0) > 0);
14041404

1405-
const bestMatch = _.maxBy(matches, m => m.match!.partiallyConsumed);
1405+
const bestMatch = _.maxBy(matches, m =>
1406+
// Use both, to ensure that fuller matches go before more partial
1407+
// matches (e.g. header/headers) when both are available
1408+
m.match!.fullyConsumed + m.match!.partiallyConsumed
1409+
);
14061410
const innerDescription = bestMatch
14071411
? bestMatch.filter.filterDescription(innerValue, isTemplate)
14081412
: '...';

test/unit/model/filters/search-filter-integration.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,7 @@ describe("Search filter model integration test:", () => {
15811581
["not(", "exchanges that do not match a given condition"],
15821582
["not(error", "excluding requests that weren't transmitted successfully"],
15831583
["not(head", "excluding exchanges by all header values"],
1584+
["not(header", "excluding exchanges by a specific header"],
15841585
["not(query^=?abc)", "excluding requests with a query string starting with ?abc"],
15851586
["not(hostname*=", "excluding requests to a hostname containing a given value"],
15861587
["not(method=POST)", "excluding POST requests"]

0 commit comments

Comments
 (0)