Skip to content

Commit 361070c

Browse files
committed
Avoid empty characters
1 parent 7ef9f39 commit 361070c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/libs/storage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@ def list(self) -> dict:
5555

5656
def set(self, key, value):
5757
"""set key data"""
58+
if isinstance(value, str):
59+
value = value.strip()
5860
return self._db.hset(self.index, key, json.dumps(value))
5961

6062
def setmany(self, **mapping):
6163
if mapping and isinstance(mapping, dict):
6264
pipe = self._db.pipeline()
6365
for k, v in iteritems(mapping):
66+
if isinstance(v, str):
67+
v = v.strip()
6468
pipe.hset(self.index, k, json.dumps(v))
6569
return pipe.execute()
6670

src/views/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ def my():
953953
#: 基于资料本身进行的统一更新
954954
allowed_fields = ["nickname", "avatar", "email"]
955955
data = {
956-
k: v
956+
k: v.strip()
957957
for k, v in iteritems(request.form.to_dict())
958958
if k in allowed_fields
959959
}
@@ -1007,6 +1007,8 @@ def my():
10071007
try:
10081008
pipe: Pipeline = g.rc.pipeline()
10091009
for k, v in iteritems(cfgs):
1010+
if isinstance(v, str):
1011+
v = v.strip()
10101012
pipe.hset(ak, k, v)
10111013
pipe.execute()
10121014
except RedisError:

0 commit comments

Comments
 (0)