Skip to content

Commit db0afdb

Browse files
authored
fix(remote_config)!: check value types before passing them to native (#6817)
* fix(remote_config)!: check value types before passing them to native BREAKING CHANGE: #setDefaults now throws if non-primitive value is being passed. We're being explicit about value types to prevent serialization of complex objects on native side, making them non-deserializable * fix(remote_config): apply correct condition * refactor(remote_config): concat exception message lines * refactor(remote_config): move params check logic out of the meethod channel * test(remote_config): verify #setDefaults checks for argument type * doc(remote_config): being explicit about value types * refactor(remote_config): throw ArgumentError with more verbose description
1 parent dc86445 commit db0afdb

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,19 @@ class RemoteConfig extends FirebasePluginPlatform with ChangeNotifier {
132132
}
133133

134134
/// Sets the default parameter values for the current instance.
135+
/// Only booleans, strings and numbers are supported as values of the map
135136
Future<void> setDefaults(Map<String, dynamic> defaultParameters) {
137+
defaultParameters.forEach(_checkIsSupportedType);
136138
return _delegate.setDefaults(defaultParameters);
137139
}
140+
141+
void _checkIsSupportedType(String key, dynamic value) {
142+
if (value is! bool && value is! num && value is! String) {
143+
throw ArgumentError(
144+
'Invalid value type "${value.runtimeType}" for key "$key". '
145+
'Only booleans, numbers and strings are supported as config values. '
146+
"If you're trying to pass a json object – convert it to string beforehand",
147+
);
148+
}
149+
}
138150
}

packages/firebase_remote_config/firebase_remote_config/test/firebase_remote_config_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ void main() {
213213
remoteConfig.setDefaults(mockParameters);
214214
verify(mockRemoteConfigPlatform.setDefaults(mockDefaultParameters));
215215
});
216+
217+
test('should throw when non-primitive value is passed', () {
218+
expect(
219+
() => remoteConfig.setDefaults({
220+
'key': {'nested': 'object'}
221+
}),
222+
throwsArgumentError,
223+
);
224+
});
216225
});
217226
});
218227
}

0 commit comments

Comments
 (0)