Skip to content

fix(messaging): tolerate non-string fields, non-list locArgs, and invalid sentTime in RemoteMessage.fromMap - #18828

Open
cynthiajoan wants to merge 2 commits into
firebase:mainfrom
cynthiajoan:agent/remote-message-parse-firebase_messaging_platform_interface-FCM-2-FCM-3
Open

cynthiajoan wants to merge 2 commits into
firebase:mainfrom
cynthiajoan:agent/remote-message-parse-firebase_messaging_platform_interface-FCM-2-FCM-3

Conversation

@cynthiajoan

@cynthiajoan cynthiajoan commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Hardens RemoteMessage.fromMap and RemoteNotification.fromMap (plus platform-specific notification sub-factories) in firebase_messaging_platform_interface against non-conforming payload field types so that a single unexpected type in a push payload does not throw a TypeError or FormatException and drop message delivery on onMessage / onMessageOpenedApp / onBackgroundMessage:

  1. String fields (senderId, category, actionIdentifier, collapseKey, from, messageId, messageType, threadId, notification title/body/*LocKey/etc.): coerce non-null values via ?.toString() instead of assuming String?.
  2. Localization argument lists (titleLocArgs, bodyLocArgs, subtitleLocArgs): in _toList, coerce iterable elements with e?.toString() ?? '' (preserving positional slots when null is present) and wrap a single non-iterable value in a 1-element <String>[value.toString()].
  3. Boolean, numeric, and sentTime fields (contentAvailable, mutableContent, ttl, sentTime, sound.critical, sound.volume): parse via safe helpers (_asBool, _asInt, _asNum, _parseSentTime) using tryParse and epoch bounds checks (|ms| <= 8,640,000,000,000,000) while keeping sentTime in milliseconds so fromMap(toMap()) round-trips losslessly.

Related Issues

None

Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See [Contributor Guide]).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the [Flutter Style Guide].
  • I signed the [CLA].
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

…ch-seconds sentTime in RemoteMessage.fromMap
@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

Comment on lines +302 to +309
if (value is Iterable) {
return value
.where((Object? e) => e != null)
.map((Object? e) => e.toString())
.toList();
}
return <String>[value.toString()];
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cynthiajoan cynthiajoan changed the title fix(messaging): tolerate non-string fields, non-list locArgs, and epoch-seconds sentTime in RemoteMessage.fromMap fix(messaging): tolerate non-string fields, non-list locArgs, and invalid sentTime in RemoteMessage.fromMap Oct 22, 2026
@cynthiajoan cynthiajoan changed the title fix(messaging): tolerate non-string fields, non-list locArgs, and invalid sentTime in RemoteMessage.fromMap fix(messaging): tolerate non-string fields, non-list locArgs, and invalid sentTime in RemoteMessage.fromMap [DO NOT MERGE, wait 5.1.0 release] Oct 23, 2026
@cynthiajoan cynthiajoan changed the title fix(messaging): tolerate non-string fields, non-list locArgs, and invalid sentTime in RemoteMessage.fromMap [DO NOT MERGE, wait 5.1.0 release] fix(messaging): tolerate non-string fields, non-list locArgs, and invalid sentTime in RemoteMessage.fromMap Oct 23, 2026
@cynthiajoan
cynthiajoan requested a review from Lyokone October 23, 2026 22:43

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants