@@ -5,6 +5,7 @@ import 'dart:io';
55import 'package:shelf/shelf.dart' ;
66import 'package:shelf/shelf_io.dart' as shelf_io;
77
8+ import 'common/cloud_run_id.dart' ;
89import 'common/on_init.dart' ;
910import 'firebase.dart' ;
1011
@@ -317,9 +318,11 @@ Future<(Request, FirebaseFunctionDeclaration?)> _tryMatchCloudEventFunction(
317318 final topicName = source.split ('/topics/' ).last;
318319
319320 // Sanitize topic name to match function naming convention
320- // Topic "my-topic" becomes function "onMessagePublished_mytopic "
321+ // Topic "my-topic" becomes function "on-message-published-mytopic "
321322 final sanitizedTopic = topicName.replaceAll ('-' , '' ).toLowerCase ();
322- final expectedFunctionName = 'onMessagePublished_$sanitizedTopic ' ;
323+ final expectedFunctionName = toCloudRunId (
324+ 'onMessagePublished_$sanitizedTopic ' ,
325+ );
323326
324327 // Try to find a matching function
325328 for (final function in functions) {
@@ -354,9 +357,10 @@ Future<(Request, FirebaseFunctionDeclaration?)> _tryMatchCloudEventFunction(
354357 // Map CloudEvent type to method name
355358 final methodName = _mapCloudEventTypeToFirestoreMethod (type);
356359 if (methodName != null ) {
360+ final methodPrefix = toCloudRunId (methodName);
357361 // Try to find a matching function by pattern matching
358362 for (final function in functions) {
359- if (! function.external && function.name.startsWith (methodName )) {
363+ if (! function.external && function.name.startsWith (methodPrefix )) {
360364 // Check if this function has a document pattern to match against
361365 if (function.documentPattern != null ) {
362366 if (_matchesDocumentPattern (
@@ -394,9 +398,10 @@ Future<(Request, FirebaseFunctionDeclaration?)> _tryMatchCloudEventFunction(
394398 // Map CloudEvent type to method name
395399 final methodName = _mapCloudEventTypeToDatabaseMethod (type);
396400 if (methodName != null ) {
401+ final methodPrefix = toCloudRunId (methodName);
397402 // Try to find a matching function by pattern matching
398403 for (final function in functions) {
399- if (! function.external && function.name.startsWith (methodName )) {
404+ if (! function.external && function.name.startsWith (methodPrefix )) {
400405 // Check if this function has a ref pattern to match against
401406 if (function.refPattern != null ) {
402407 if (_matchesRefPattern (refPath, function.refPattern! )) {
@@ -440,7 +445,9 @@ Future<(Request, FirebaseFunctionDeclaration?)> _tryMatchCloudEventFunction(
440445 RegExp ('[^a-zA-Z0-9]' ),
441446 '' ,
442447 );
443- final expectedFunctionName = '${methodName }_$sanitizedBucket ' ;
448+ final expectedFunctionName = toCloudRunId (
449+ '${methodName }_$sanitizedBucket ' ,
450+ );
444451
445452 // Try to find a matching function
446453 for (final function in functions) {
0 commit comments