diff --git a/analysis_options.yaml b/analysis_options.yaml index 2ea531761..85b95567f 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -89,7 +89,7 @@ linter: # - cascade_invocations # doesn't match the typical style of this repo - cast_nullable_to_non_nullable # - close_sinks # not reliable enough - # - collection_methods_unrelated_type # TODO(jsuya): Different from flutter/packages: temporary. Disabled to pass CI on Flutter 3.47.0; re-enable after fixing existing violations (https://github.com/flutter-tizen/plugins/issues/1089). + - collection_methods_unrelated_type - combinators_ordering # - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142 - conditional_uri_does_not_exist diff --git a/packages/tizen_bundle/CHANGELOG.md b/packages/tizen_bundle/CHANGELOG.md index 85d37e27e..8a8c31980 100644 --- a/packages/tizen_bundle/CHANGELOG.md +++ b/packages/tizen_bundle/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.5 + +* Fix `operator []` and `remove()` to not throw on non-String keys. + ## 0.1.4 * Update integration tests. diff --git a/packages/tizen_bundle/example/integration_test/tizen_bundle_test.dart b/packages/tizen_bundle/example/integration_test/tizen_bundle_test.dart index 705bf2173..5b4de2481 100644 --- a/packages/tizen_bundle/example/integration_test/tizen_bundle_test.dart +++ b/packages/tizen_bundle/example/integration_test/tizen_bundle_test.dart @@ -132,11 +132,13 @@ void main() { expect(bundle['nonExistentKey'], isNull); }); - test('returns null when key is null', () async { + test('returns null when the key is not a String', () async { final Bundle bundle = Bundle(); bundle['someKey'] = 'someValue'; - // The implementation accepts Object? key and returns null for null. - expect(bundle[null], isNull); + // operator[] takes an Object?, so it must accept any key. + for (final Object? key in [null, 42, true]) { + expect(bundle[key], isNull); + } }); test('returns the correct value after key is overwritten', () async { @@ -199,10 +201,13 @@ void main() { // remove() // --------------------------------------------------------------------------- group('remove()', () { - test('remove(null) is a no-op and does not throw', () async { + test('removing a key that is not a String is a no-op', () async { final Bundle bundle = Bundle(); bundle['key'] = 'value'; - expect(() => bundle.remove(null), returnsNormally); + // remove() takes an Object?, so it must accept any key. + for (final Object? key in [null, 42, true]) { + expect(() => bundle.remove(key), returnsNormally); + } expect(bundle.length, 1); }); diff --git a/packages/tizen_bundle/lib/tizen_bundle.dart b/packages/tizen_bundle/lib/tizen_bundle.dart index 68f2e2164..a72ae44a1 100644 --- a/packages/tizen_bundle/lib/tizen_bundle.dart +++ b/packages/tizen_bundle/lib/tizen_bundle.dart @@ -88,12 +88,12 @@ class Bundle extends MapMixin { /// The value for the given [key], or null if [key] is not in the bundle. @override Object? operator [](Object? key) { - if (key == null) { + if (key is! String) { return null; } Object? value; - final int type = _getType(key as String); + final int type = _getType(key); if (type == bundle_type.BUNDLE_TYPE_STR) { value = _getString(key); } else if (type == bundle_type.BUNDLE_TYPE_STR_ARRAY) { @@ -131,13 +131,12 @@ class Bundle extends MapMixin { /// Removes [key] and its associated value, if present, from the bundle. @override void remove(Object? key) { - if (key == null) { + if (key is! String) { return; } final int ret = using((Arena arena) { - final String keyName = key as String; - return tizen.bundle_del(_handle, keyName.toNativeChar(allocator: arena)); + return tizen.bundle_del(_handle, key.toNativeChar(allocator: arena)); }); if (ret != bundle_error_e.BUNDLE_ERROR_NONE && ret != bundle_error_e.BUNDLE_ERROR_KEY_NOT_AVAILABLE) { diff --git a/packages/tizen_bundle/pubspec.yaml b/packages/tizen_bundle/pubspec.yaml index b1d626d53..cbe71d06f 100644 --- a/packages/tizen_bundle/pubspec.yaml +++ b/packages/tizen_bundle/pubspec.yaml @@ -2,7 +2,7 @@ name: tizen_bundle description: Tizen data bundle APIs. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/main/packages/tizen_bundle -version: 0.1.4 +version: 0.1.5 environment: sdk: ">=3.1.0 <4.0.0"