commit | f337050407872ef3cfba47033698061758e57762 | [log] [tgz] |
---|---|---|
author | hellohuanlin <41930132+hellohuanlin@users.noreply.github.com> | Wed Jul 05 22:42:19 2023 -0700 |
committer | GitHub <noreply@github.com> | Thu Jul 06 05:42:19 2023 +0000 |
tree | 9a734605fa27830e62fce7cd764833c4283adc77 | |
parent | 61df84d1bdbd45c04b58e63c351b355227a6899e [diff] |
[pigeon]fix a crash when casting NSNull to an Array (#4289) Fixes a crash introduced in https://github.com/flutter/packages/pull/3658: ``` static func fromList(_ list: [Any?]) -> NativeAuthSession? { if let userPoolTokensList = list[2] as! [Any?]? {} } ``` where `list[2]` is `NSNull`, which is not an Optional, hence can't be casted to `[Any?]?`. Recall that `nilOrValue` helper is created for this purpose. So the fix is simply: ``` static func fromList(_ list: [Any?]) -> NativeAuthSession? { if let userPoolTokensList: [Any?] = nilOrValue(list[2]) {} // <- HERE } ``` ## Why didn't we catch this regression Missing unit tests - we did not test `NSNull` fields to ensure `nilOrValue` works for them. ## Why did it work in previous version? It's surprising that this worked fine before! The original code is: ``` static func fromList(_ list: [Any]) -> NativeAuthSession? { if let userPoolTokensList = list[2] as! [Any]? {} } ``` From [my previous PR](https://github.com/flutter/flutter/issues/129283), we know that list[2] is an implicit optional (that contains a NSNull value). I think Swift made an exception here when casting implicit optional NSNull (either intentionally or unintentionally). *List which issues are fixed by this PR. You must list at least one issue.* Fixes https://github.com/flutter/flutter/issues/129283 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
This repo is a companion repo to the main flutter repo. It contains the source code for Flutter's first-party packages (i.e., packages developed by the core Flutter team). Check the packages
directory to see all packages.
These packages are also available on pub.
Please file any issues, bugs, or feature requests in the main flutter repo. Issues pertaining to this repository are labeled “package”.
If you wish to contribute a new package to the Flutter ecosystem, please see the documentation for developing packages. You can store your package source code in any GitHub repository (the present repo is only intended for packages developed by the core Flutter team). Once your package is ready you can publish to the pub repository.
If you wish to contribute a change to any of the existing packages in this repo, please review our contribution guide, and send a pull request.
These are the packages hosted in this repository: