Repository navigation
fix(messaging): tolerate non-string fields, non-list locArgs, and invalid sentTime in RemoteMessage.fromMap - #18828
Conversation
…ch-seconds sentTime in RemoteMessage.fromMap
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
| if (value is Iterable) { | ||
| return value | ||
| .where((Object? e) => e != null) | ||
| .map((Object? e) => e.toString()) | ||
| .toList(); | ||
| } | ||
| return <String>[value.toString()]; | ||
| } |
There was a problem hiding this comment.
_toList drops nulls, which misaligns positional loc args.** bodyLocArgs: [null, 'Bob'] becomes ['Bob'], so a loc-key like "%1$@ invited %2$@" puts Bob in the first slot. Previously this threw; now it renders the wrong text with no error. Suggest mapping null to '' instead of filtering it out, so positions are kept.
| if (raw == null) return null; | ||
| // Convert positive 10-digit epoch-seconds values (e.g. Apple google.c.a.ts) | ||
| // to milliseconds since epoch. | ||
| if (raw > 0 && raw < 10000000000) { |
There was a problem hiding this comment.
fromMap is no longer the inverse of toMap.** toMap() always emits milliseconds, but fromMap now reads any positive value below 1e10 as seconds. RemoteMessage(sentTime: DateTime.fromMillisecondsSinceEpoch(5000)) round-trips to 5,000,000 ms. That affects anyone who persists toMap() or passes it across isolates and rehydrates it, as well as tests and fakes that use small epoch values.
Description
Hardens
RemoteMessage.fromMapandRemoteNotification.fromMap(plus platform-specific notification sub-factories) infirebase_messaging_platform_interfaceagainst non-conforming payload field types so that a single unexpected type in a push payload does not throw aTypeErrororFormatExceptionand drop message delivery ononMessage/onMessageOpenedApp/onBackgroundMessage:senderId,category,actionIdentifier,collapseKey,from,messageId,messageType,threadId, notificationtitle/body/*LocKey/etc.): coerce non-null values via?.toString()instead of assumingString?.titleLocArgs,bodyLocArgs,subtitleLocArgs): in_toList, coerce iterable elements withe?.toString() ?? ''(preserving positional slots whennullis present) and wrap a single non-iterable value in a 1-element<String>[value.toString()].sentTimefields (contentAvailable,mutableContent,ttl,sentTime,sound.critical,sound.volume): parse via safe helpers (_asBool,_asInt,_asNum,_parseSentTime) usingtryParseand epoch bounds checks (|ms| <= 8,640,000,000,000,000) while keepingsentTimein milliseconds sofromMap(toMap())round-trips losslessly.Related Issues
None
Checklist
///).melos run analyze) does not report any problems on my PR.Breaking Change