fix(issues): Escape reserved tag keys in tag drawer value links

Clicking a value in the tag details drawer built the search as
`key:"value"` with the raw tag key. For a custom tag named after a
reserved search key, like `project_id`, the events page searched the
built-in field instead of the tag and errored.

Escape the key with `escapeIssueTagKey`, which the value actions menu
in the same file already uses, so the link becomes
`tags[project_id]:"value"`.
This commit is contained in:
dualfroz committed 2026-10-17 04:21:20 +02:00
1 parent 916dae8061
commit 42fa6c159c
2 files changed
+47 -1

No files matched your search

@@ -437,6 +437,52 @@ describe('TagDetailsDrawerContent', () => {
expect(await screen.findByText('id:123')).toBeInTheDocument();
});
it('escapes reserved tag keys in the tag value link', async () => {
const projectIdTag: TagWithTopValues = {
key: 'project_id',
name: 'Project_id',
totalValues: 3,
uniqueValues: 1,
topValues: [
{
count: 3,
name: '42',
value: '42',
key: 'project_id',
lastSeen: '2024-01-01T00:00:00Z',
firstSeen: '2024-01-01T00:00:00Z',
},
],
};
MockApiClient.addMockResponse({
url: '/organizations/org-slug/issues/1/tags/project_id/',
body: projectIdTag,
});
MockApiClient.addMockResponse({
url: '/organizations/org-slug/issues/1/tags/project_id/values/',
body: [
{
count: 3,
firstSeen: '2024-01-01T00:00:00Z',
lastSeen: '2024-01-01T00:00:00Z',
name: '42',
value: '42',
key: 'project_id',
},
],
});
render(<TagDetailsDrawerContent group={group} />, {
initialRouterConfig: makeInitialRouterConfig('project_id'),
});
expect(await screen.findByRole('link', {name: '42'})).toHaveAttribute(
'href',
'/organizations/org-slug/issues/1/events/recommended/?query=tags%5Bproject_id%5D%3A%2242%22'
);
});
it('renders empty tag value label and hides copy action', async () => {
const makeTopValue = (value: string, count: number) => ({
count,
@@ -186,7 +186,7 @@ function TagDetailsRow({
query: undefined,
}
: {
query: tagValue.query || `${key}:"${tagValue.value}"`,
query: tagValue.query || `${escapeIssueTagKey(key)}:"${tagValue.value}"`,
};
const allEventsLocation = {