Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/tizen_bundle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.5

* Fix `operator []` and `remove()` to not throw on non-String keys.

## 0.1.4

* Update integration tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Object?>[null, 42, true]) {
expect(bundle[key], isNull);
}
});

test('returns the correct value after key is overwritten', () async {
Expand Down Expand Up @@ -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 <Object?>[null, 42, true]) {
expect(() => bundle.remove(key), returnsNormally);
}
expect(bundle.length, 1);
});

Expand Down
9 changes: 4 additions & 5 deletions packages/tizen_bundle/lib/tizen_bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ class Bundle extends MapMixin<String, Object> {
/// 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) {
Expand Down Expand Up @@ -131,13 +131,12 @@ class Bundle extends MapMixin<String, Object> {
/// 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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/tizen_bundle/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading