Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,16 @@ describe('FormattedQuery', () => {

expect(screen.getByText(textWithMarkupMatcher('has foo'))).toBeInTheDocument();
});

it('renders an escaped asterisk with the escape visible', () => {
render(<FormattedQuery {...defaultProps} query={'message:foo\\*bar'} />);

expect(screen.getByText('foo\\*bar')).toBeInTheDocument();
});

it('renders a wildcard asterisk without an escape', () => {
render(<FormattedQuery {...defaultProps} query="message:foo*bar" />);

expect(screen.getByText('foo*bar')).toBeInTheDocument();
});
});
16 changes: 13 additions & 3 deletions static/app/components/searchQueryBuilder/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2748,11 +2748,21 @@ describe('SearchQueryBuilder', () => {
});
});

it('renders escaped asterisks as a bare asterisk in the filter chip', async () => {
it('renders an escaped asterisk with the escape visible in the filter chip', async () => {
render(
<SearchQueryBuilder {...defaultProps} initialQuery={'browser.name:foo\\*'} />
);

expect(
await within(
screen.getByRole('button', {name: 'Edit value for filter: browser.name'})
).findByText('foo\\*')
).toBeInTheDocument();
});

it('renders a wildcard asterisk without an escape in the filter chip', async () => {
render(<SearchQueryBuilder {...defaultProps} initialQuery="browser.name:foo*" />);

expect(
await within(
screen.getByRole('button', {name: 'Edit value for filter: browser.name'})
Expand Down Expand Up @@ -5621,7 +5631,7 @@ describe('SearchQueryBuilder', () => {
).toBeInTheDocument();
});

it('escapes * for is op but not contains op', async () => {
it('renders the escaped asterisk for the contains suggestion but a wildcard for the is suggestion', async () => {
render(
<SearchQueryBuilder
{...defaultProps}
Expand All @@ -5635,7 +5645,7 @@ describe('SearchQueryBuilder', () => {
const options = within(screen.getByRole('listbox')).getAllByRole('option');
expect(options).toHaveLength(2);

expect(options[0]).toHaveTextContent('span.description contains test*');
expect(options[0]).toHaveTextContent('span.description contains test\\*');
expect(options[1]).toHaveTextContent('span.description is test*');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('unescapeAsteriskSearchValue', () => {
});

describe('formatFilterValue', () => {
it('unescapes asterisks for unquoted values', () => {
it('preserves escaped asterisks for unquoted values', () => {
expect(
formatFilterValue({
token: {
Expand All @@ -206,19 +206,55 @@ describe('formatFilterValue', () => {
quoted: false,
} as any,
})
).toBe('****');
).toBe('\\*\\*\\*\\*');
});

it('unescapes asterisks for quoted values', () => {
it('preserves escaped asterisks for quoted values', () => {
expect(
formatFilterValue({
token: {
type: Token.VALUE_TEXT,
text: '"foo\\\\*bar"',
text: '"foo\\*bar"',
value: 'foo\\*bar',
quoted: true,
} as any,
})
).toBe('foo*bar');
).toBe('foo\\*bar');
});

it('renders an escaped asterisk differently from a wildcard asterisk', () => {
const escaped = formatFilterValue({
token: {
type: Token.VALUE_TEXT,
text: 'foo\\*bar',
value: 'foo\\*bar',
quoted: false,
} as any,
});
const wildcard = formatFilterValue({
token: {
type: Token.VALUE_TEXT,
text: 'foo*bar',
value: 'foo*bar',
quoted: false,
} as any,
});

expect(escaped).toBe('foo\\*bar');
expect(wildcard).toBe('foo*bar');
expect(escaped).not.toBe(wildcard);
});

it('preserves a literal backslash before a wildcard asterisk', () => {
expect(
formatFilterValue({
token: {
type: Token.VALUE_TEXT,
text: 'foo\\\\*bar',
value: 'foo\\\\*bar',
quoted: false,
} as any,
})
).toBe('foo\\\\*bar');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ export function formatFilterValue({
return content;
}

return unescapeAsteriskSearchValue(
token.quoted ? unescapeTagValue(content) : content
);
return token.quoted ? unescapeTagValue(content) : content;
}
case Token.VALUE_RELATIVE_DATE:
return t('%s', `${token.value}${token.unit} ago`);
Expand Down
Loading