From de24893f81dba085efffc77a574fee8a4524916c Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Mon, 13 Jan 2025 07:38:39 +1030 Subject: [PATCH] feat: trim whitespace from 'name' and 'rename' fields in handle_item function --- backend/app/data/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/app/data/__init__.py b/backend/app/data/__init__.py index 129ac66..61490f9 100644 --- a/backend/app/data/__init__.py +++ b/backend/app/data/__init__.py @@ -105,12 +105,17 @@ def handle_item(category, name): return jsonify({"error": f"Failed to delete {file_name}"}), 500 elif request.method == 'POST': + # If a file already exists with that name, conflict if os.path.exists(file_path): return jsonify({"error": f"File {file_name} already exists"}), 409 try: data = request.get_json() + + if data and 'name' in data: + data['name'] = data['name'].strip() + if validate(data, category): save_yaml_file(file_path, data, category) return jsonify( @@ -126,6 +131,12 @@ def handle_item(category, name): try: data = request.get_json() + + if data and 'name' in data: + data['name'] = data['name'].strip() + if data and 'rename' in data: + data['rename'] = data['rename'].strip() + update_yaml_file(file_path, data, category) return jsonify( {"message": f"Successfully updated {file_name}"}), 200