Commit 1af00903 authored by Axel Garcia's avatar Axel Garcia Committed by Mike Greiling

Set & token as numeric on filtered search tokens

Fixes https://gitlab.com/gitlab-org/gitlab/-/issues/213154.

This adds the & token to the prefixed-tokens regex/array so the symbol
gets stripped when processed.

Involves a bit of refactoring to improve readability.
parent 5f0667ee
......@@ -6,7 +6,7 @@ export default class FilteredSearchTokenizer {
// Values that start with a double quote must end in a double quote (same for single)
const tokenRegex = new RegExp(
`(${allowedKeys.join('|')}):(=|!=)?([~%@]?)(?:('[^']*'{0,1})|("[^"]*"{0,1})|(\\S+))`,
`(${allowedKeys.join('|')}):(=|!=)?([~%@&]?)(?:('[^']*'{0,1})|("[^"]*"{0,1})|(\\S+))`,
'g',
);
const tokens = [];
......@@ -15,17 +15,19 @@ export default class FilteredSearchTokenizer {
const searchToken =
input
.replace(tokenRegex, (match, key, operator, symbol, v1, v2, v3) => {
const prefixedTokens = ['~', '%', '@', '&'];
const comparisonTokens = ['!=', '='];
let tokenValue = v1 || v2 || v3;
let tokenSymbol = symbol;
let tokenIndex = '';
let tokenOperator = operator;
if (tokenValue === '~' || tokenValue === '%' || tokenValue === '@') {
if (prefixedTokens.includes(tokenValue)) {
tokenSymbol = tokenValue;
tokenValue = '';
}
if (tokenValue === '!=' || tokenValue === '=') {
if (comparisonTokens.includes(tokenValue)) {
tokenOperator = tokenValue;
tokenValue = '';
}
......
---
title: Fix failing filtered search when re-submitting epic tokens
merge_request: 35205
author:
type: fixed
import IssuableFilteredSearchTokenKeys from 'ee/filtered_search/issuable_filtered_search_token_keys';
import FilteredSearchTokenizer from '~/filtered_search/filtered_search_tokenizer';
describe('Filtered Search Tokenizer', () => {
const allowedKeys = IssuableFilteredSearchTokenKeys.getKeys();
describe('processTokens', () => {
describe('epic tokens', () => {
it.each`
searchQuery | operator
${'epic:=&36'} | ${'='}
${'epic:!=&36'} | ${'!='}
`('returns for input containing $searchQuery', ({ searchQuery, operator }) => {
const results = FilteredSearchTokenizer.processTokens(searchQuery, allowedKeys);
expect(results.searchToken).toBe('');
expect(results.tokens).toHaveLength(1);
expect(results.tokens[0].key).toBe('epic');
expect(results.tokens[0].operator).toBe(operator);
expect(results.tokens[0].symbol).toBe('&');
expect(results.tokens[0].value).toBe('36');
});
it('returns for input containing string values', () => {
const results = FilteredSearchTokenizer.processTokens('epic:=any', allowedKeys);
expect(results.searchToken).toBe('');
expect(results.tokens).toHaveLength(1);
expect(results.tokens[0].key).toBe('epic');
expect(results.tokens[0].operator).toBe('=');
expect(results.tokens[0].symbol).toBe('');
expect(results.tokens[0].value).toBe('any');
});
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment