@@ -274,6 +274,31 @@ function lastFourNumbersFromCardName(cardName: string | undefined): string {
274274 return match [ 1 ] ;
275275}
276276
277+ /**
278+ * Checks if a card matches a given card identifier (encrypted card number or card name).
279+ * Uses exact match for encrypted card numbers, and normalized string comparison
280+ * for card names to handle special character differences from OAuth providers (e.g., ® vs no ®).
281+ *
282+ * @param card - The card to check
283+ * @param encryptedCardNumber - The encrypted card number to match against
284+ * @param cardName - The card name to match against
285+ * @returns true if the card matches either identifier
286+ */
287+ function isMatchingCard ( card : Card , encryptedCardNumber : string , cardName : string ) : boolean {
288+ if ( card . encryptedCardNumber === encryptedCardNumber ) {
289+ return true ;
290+ }
291+
292+ if ( ! card . cardName || ! cardName ) {
293+ return false ;
294+ }
295+
296+ // Normalize both strings to remove special characters (®, ™, ©, etc.)
297+ // This handles differences between OAuth provider card names and stored card names
298+ const normalize = ( str : string ) => str . replaceAll ( / [ ^ \w \s - ] / g, '' ) . trim ( ) ;
299+ return normalize ( card . cardName ) === normalize ( cardName ) ;
300+ }
301+
277302function getMCardNumberString ( cardNumber : string ) : string {
278303 return cardNumber . replaceAll ( / \s / g, '' ) ;
279304}
@@ -965,7 +990,7 @@ function isCardAlreadyAssigned(cardNumberToCheck: string, workspaceCardFeeds: On
965990 }
966991 const { cardList, ...assignedCards } = workspaceCards ;
967992 return Object . values ( assignedCards ) . some (
968- ( card ) => card ? .pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE && ( card ?. encryptedCardNumber === cardNumberToCheck || card ?. cardName === cardNumberToCheck ) ,
993+ ( card ) => card && card . pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE && isMatchingCard ( card , cardNumberToCheck , cardNumberToCheck ) ,
969994 ) ;
970995 } ) ;
971996}
@@ -1043,6 +1068,7 @@ export {
10431068 isCardConnectionBroken ,
10441069 isSmartLimitEnabled ,
10451070 lastFourNumbersFromCardName ,
1071+ isMatchingCard ,
10461072 hasIssuedExpensifyCard ,
10471073 isExpensifyCardFullySetUp ,
10481074 filterInactiveCards ,
0 commit comments