Repository navigation
Conversation
AnyEncodable matched NSNumber 0 and 1 as Bool before Double, so httpsCallable().stream() sent those values as false and true.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request refactors the encoding logic in CodecUtility.swift by introducing helper methods to simplify the serialization of NSNumber and other method-channel values, and adds a comprehensive test suite in CodecUtilityEncodingTests.swift. Feedback highlights a potential regression where large UInt64 values exceeding Int64.max could suffer from silent integer overflow when encoded as int64Value. A code suggestion is provided to inspect the Objective-C type encoding (objCType) to safely handle and encode these large unsigned integers.
…coding NSNumber values above Int64.max report objCType Q and wrapped through int64Value. Float values gained digits through doubleValue. Both now encode with their own width, as the previous switch did.
|
@SelaseKay Thanks, added in c1fdf45. The
They use the existing emulator function, so no function changes are needed. On an iOS 18.5 simulator both tests fail with the previous encoder ( |
|
@googlebot I signed it! @SelaseKay the e2e tests are in c1fdf45, and this is ready for another look when you have a moment. The CI runs for the latest commit are waiting for workflow approval. |
c1fdf45 to
836b424
Compare
Description
httpsCallable().stream()on Apple encodes numeric0and1as JSONfalseandtrue.AnyEncodable.encodematchedas Boolbefore any numeric cast. Flutter delivers both booleans and numbers asNSNumber, and Swift'sas Boolsucceeds forNSNumber0and1. A streamed payload such as{"timezoneOffset": 1.0}therefore arrives as{"timezoneOffset": true}. Other numbers, including2,-1, and5.5, were already preserved. Non-streamingcall()does not use this encoder.The encoder now treats a value as a boolean only when its Core Foundation type is
CFBoolean. OtherNSNumbervalues encode as JSON numbers:objCTypeQ(unsigned values aboveInt64.max) encodes withuint64Value, so it does not wrap.objCTypef(Float) encodes withfloatValue, soFloat(0.1)stays0.1.Double, and other integers asInt64.This keeps the
UInt64andFloatbehavior of the previousswitch. The macOSCodecUtility.swiftis a symlink to the iOS source, so both platforms get the change.Related Issues
Fixes #18982.
Test plan
E2E (
example/integration_test/e2e_test.dart,HttpsCallable Streamgroup), using the existingtestFunctionDefaultRegionemulator function:accepts number values 0 and 1streams0,1,0.0, and1.0and expects the function to see anumber.keeps number values 0 and 1 in a [Map] and [List]streams arawDatamap with0,1,0.0,1.0,true,false, and a mixed list, and expects it to round-trip unchanged.Run locally on an iPhone 16 simulator (iOS 18.5) with the CI steps (
generate-dummy-firebase-configs.dart --functions-native,firebase emulators:exec):0reaches the function asboolean, andzerocomes back asfalse.Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]).This will ensure a smooth and quick review process. Updating the
pubspec.yamland changelogs is not required.///).melos run analyze) does not report any problems on my PR.Tests were run locally on iOS; Android, macOS, and web e2e runs are pending CI.
flutter analyzeanddart formatare clean for the e2e file, and theanalyzeCI job passed on the first commit.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?