Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Jul 10, 2024
1 parent d3f99cd commit fe7c25c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 3 additions & 12 deletions admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def set_banner() -> Response:
:returns: Redirect to admin page with status message
"""
banner_message = request.form.get('banner', '').strip()
banner_message = escape_html(banner_message) # Ensure safe text
banner_message = escape(banner_message) # Ensure safe text

# Message length check
error_message, is_valid = length_check(banner_message)
Expand Down Expand Up @@ -97,16 +97,6 @@ def remove_banner() -> Response:
return save_settings(settings, flash_msg)


def escape_html(text: str) -> str:
"""Escape HTML special characters in text.
:param text: Text to escape
:returns: Escaped text
"""
return escape(text)


def save_settings(settings: Dict[str, Any], flash_msg: str) -> Response:
"""Apply and persist settings.
Expand All @@ -117,11 +107,12 @@ def save_settings(settings: Dict[str, Any], flash_msg: str) -> Response:
"""
config_file_path = path.join(app.config['APP_SHARED_FOLDER'], 'banner_settings.json')
app.config.update(settings)

try:
with open(config_file_path, 'w') as file:
json.dump(settings, file)
flash(flash_msg, 'success')
except IOError:
except Exception:
flash("Failed to save settings", "danger")
return "Failed to save settings", 500

Expand Down
2 changes: 0 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def load_banner_config():
'banner_importance': settings.get('banner_importance', False),
'banner_message': settings.get('banner_message', '')
}
except json.JSONDecodeError:
return default_config
except Exception:
return default_config

Expand Down

0 comments on commit fe7c25c

Please sign in to comment.