Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 0ff11a5

Browse files
authored
Ban string values which clash with special prefixes (#798)
1 parent 46b5486 commit 0ff11a5

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

packages/shared_preferences/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.3
2+
3+
* Prevent strings that match special prefixes from being saved. This is a bugfix that prevents apps from accidentally setting special values that would be interpreted incorrectly.
4+
15
## 0.4.2
26

37
* Updated Gradle tooling to match Android Studio 3.1.2.

packages/shared_preferences/android/src/main/java/io/flutter/plugins/sharedpreferences/SharedPreferencesPlugin.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,15 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
137137
status = editor.commit();
138138
break;
139139
case "setString":
140-
status = preferences.edit().putString(key, (String) call.argument("value")).commit();
140+
String value = (String) call.argument("value");
141+
if (value.startsWith(LIST_IDENTIFIER) || value.startsWith(BIG_INTEGER_PREFIX)) {
142+
result.error(
143+
"StorageError",
144+
"This string cannot be stored as it clashes with special identifier prefixes.",
145+
null);
146+
return;
147+
}
148+
status = preferences.edit().putString(key, value).commit();
141149
break;
142150
case "setStringList":
143151
List<String> list = call.argument("value");

packages/shared_preferences/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for reading and writing simple key-value pairs.
33
Wraps NSUserDefaults on iOS and SharedPreferences on Android.
44
author: Flutter Team <flutter-dev@googlegroups.com>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences
6-
version: 0.4.2
6+
version: 0.4.3
77

88
flutter:
99
plugin:

0 commit comments

Comments
 (0)