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
13 changes: 11 additions & 2 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ import interceptAnonymousUser from './interceptAnonymousUser';
import Navigation from './Navigation/Navigation';
import Parser from './Parser';
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
import {arePaymentsEnabled, canSendInvoice, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, getSubmitToAccountID, isPaidGroupPolicy, isPolicyPayer} from './PolicyUtils';
import {
arePaymentsEnabled,
canSendInvoice,
getCleanedTagName,
getGroupPaidPoliciesWithExpenseChatEnabled,
getPolicy,
getSubmitToAccountID,
isPaidGroupPolicy,
isPolicyPayer,
} from './PolicyUtils';
import {
getIOUActionForReportID,
getOriginalMessage,
Expand Down Expand Up @@ -2363,7 +2372,7 @@ function getTagSections(data: OnyxTypes.SearchResults['data'], queryJSON: Search
// Format the tag name - use translated "No tag" for empty values so it sorts alphabetically
const rawTag = tagGroup.tag;
const isEmptyTag = !rawTag || rawTag === CONST.SEARCH.TAG_EMPTY_VALUE || rawTag === '(untagged)';
const formattedTag = isEmptyTag ? translate('search.noTag') : rawTag;
const formattedTag = isEmptyTag ? translate('search.noTag') : getCleanedTagName(rawTag);

tagSections[key] = {
groupedBy: CONST.SEARCH.GROUP_BY.TAG,
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3425,6 +3425,36 @@ describe('SearchUIUtils', () => {
).toStrictEqual(transactionTagGroupListItems);
});

it('should unescape colons in tag names when grouping by tag', () => {
// Backend sends tags with escaped colons (e.g., 'Parent\: Child')
const escapedTagName = 'Parent\\: Child';
const dataWithEscapedTag: OnyxTypes.SearchResults['data'] = {
personalDetailsList: {},
[`${CONST.SEARCH.GROUP_PREFIX}${escapedTagName}` as const]: {
tag: escapedTagName,
count: 1,
currency: 'USD',
total: 100,
},
};

const [result] = SearchUIUtils.getSections({
type: CONST.SEARCH.DATA_TYPES.EXPENSE,
data: dataWithEscapedTag,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
bankAccountList: {},
groupBy: CONST.SEARCH.GROUP_BY.TAG,
}) as [TransactionTagGroupListItemType[], number];

// formattedTag should have unescaped colons for display
expect(result.at(0)?.formattedTag).toBe('Parent: Child');
// Original tag property should remain unchanged
expect(result.at(0)?.tag).toBe(escapedTagName);
});

it('should handle empty tag values correctly', () => {
const dataWithEmptyTag: OnyxTypes.SearchResults['data'] = {
personalDetailsList: {},
Expand Down
Loading