Skip to content

Commit 1bf1dd6

Browse files
SharedPreferences: fix None handling
1 parent 181a10c commit 1bf1dd6

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

internal_filesystem/lib/mpos/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def __init__(self, preferences):
172172

173173
def put_string(self, key, value):
174174
"""Store a string value."""
175-
self.temp_data[key] = str(value)
175+
self.temp_data[key] = None if value is None else str(value)
176176
return self
177177

178178
def put_int(self, key, value):

tests/test_shared_preferences.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,14 @@ def test_none_values(self):
432432
# Getting a nonexistent key should return None or default
433433
self.assertIsNone(prefs.get_string("nonexistent"))
434434

435+
def test_put_string_none_value(self):
436+
"""Test that putting None stores and returns a real None."""
437+
prefs = SharedPreferences(self.test_app_name)
438+
prefs.edit().put_string("auto_start_app_early", None).commit()
439+
440+
prefs2 = SharedPreferences(self.test_app_name)
441+
self.assertIsNone(prefs2.get_string("auto_start_app_early"))
442+
435443
def test_special_characters_in_keys(self):
436444
"""Test keys with special characters."""
437445
prefs = SharedPreferences(self.test_app_name)

0 commit comments

Comments
 (0)