Skip to content

Commit

Permalink
fix: support search for tags that has colon inside (#7998)
Browse files Browse the repository at this point in the history
Previously we expected the tag to look like `type:value`. Now we allow
everything after first colon, as the value and not break query
`type:this:still:is:value`.
  • Loading branch information
sjaanus authored Aug 28, 2024
1 parent d5e4544 commit 3d22f6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/lib/features/feature-search/feature-search-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,11 @@ const applyMultiQueryParams = (
): void => {
queryParams.forEach((param) => {
const values = param.values.map((val) =>
(Array.isArray(fields) ? val.split(':') : [val]).map((s) =>
s.trim(),
),
(Array.isArray(fields)
? val.split(/:(.+)/).filter(Boolean)
: [val]
).map((s) => s.trim()),
);

const baseSubQuery = createBaseQuery(values);

switch (param.operator) {
Expand Down
14 changes: 14 additions & 0 deletions src/lib/features/feature-search/feature.search.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,20 @@ test('should filter features by tag', async () => {
await filterFeaturesByTag('EXCLUDE_ALL:simple,simple:jest', 400);
});

test('should filter features by tag that has colon inside', async () => {
await app.createFeature('my_feature_a');
await app.addTag('my_feature_a', {
type: 'simple',
value: 'my_tag:colon',
});

const { body } = await filterFeaturesByTag('INCLUDE:simple:my_tag:colon');

expect(body).toMatchObject({
features: [{ name: 'my_feature_a' }],
});
});

test('should filter features by environment status', async () => {
await app.createFeature('my_feature_a');
await app.createFeature('my_feature_b');
Expand Down
2 changes: 1 addition & 1 deletion src/lib/openapi/spec/feature-search-query-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const featureSearchQueryParameters = [
schema: {
type: 'string',
pattern:
'^(INCLUDE|DO_NOT_INCLUDE|INCLUDE_ALL_OF|INCLUDE_ANY_OF|EXCLUDE_IF_ANY_OF|EXCLUDE_ALL):(?:\\s*[^,:]+:[^,:]+\\s*)(?:,\\s*[^,:]+:[^,:]+\\s*)*$',
'^(INCLUDE|DO_NOT_INCLUDE|INCLUDE_ALL_OF|INCLUDE_ANY_OF|EXCLUDE_IF_ANY_OF|EXCLUDE_ALL):([^:,]+:.+?)(,\\s*[^:,]+:.+?)*$',
example: 'INCLUDE:simple:my_tag',
},
description:
Expand Down

0 comments on commit 3d22f6e

Please sign in to comment.