fix: validate name/notes constraints in edit flow

This commit is contained in:
Xiaolan Bot
2026-02-22 11:30:22 +08:00
parent 095e88cad3
commit 052966e07c

View File

@@ -1163,6 +1163,16 @@ async def edit_new_value_received(update: Update, context: CallbackContext):
if message_to_reply: if message_to_reply:
await message_to_reply.reply_text("费用必须是有效的非负数字。") await message_to_reply.reply_text("费用必须是有效的非负数字。")
validation_failed = True validation_failed = True
elif field == 'name':
new_value = str(new_value).strip()
if not new_value:
if message_to_reply:
await message_to_reply.reply_text("名称不能为空。")
validation_failed = True
elif len(new_value) > MAX_NAME_LEN:
if message_to_reply:
await message_to_reply.reply_text(f"名称过长,请控制在 {MAX_NAME_LEN} 个字符以内。")
validation_failed = True
elif field == 'currency': elif field == 'currency':
new_value = str(new_value).upper() new_value = str(new_value).upper()
if not (len(new_value) == 3 and new_value.isalpha()): if not (len(new_value) == 3 and new_value.isalpha()):
@@ -1182,6 +1192,14 @@ async def edit_new_value_received(update: Update, context: CallbackContext):
if message_to_reply: if message_to_reply:
await message_to_reply.reply_text("续费方式只能为 auto 或 manual。") await message_to_reply.reply_text("续费方式只能为 auto 或 manual。")
validation_failed = True validation_failed = True
elif field == 'notes':
note_val = str(new_value).strip()
if note_val and len(note_val) > MAX_NOTES_LEN:
if message_to_reply:
await message_to_reply.reply_text(f"备注过长,请控制在 {MAX_NOTES_LEN} 个字符以内。")
validation_failed = True
else:
new_value = note_val if note_val else None
elif field == 'category': elif field == 'category':
new_value = str(new_value).strip() new_value = str(new_value).strip()
if not new_value: if not new_value: