From 38e9d268e653d3ffda57b679fff9db32d65fde9c Mon Sep 17 00:00:00 2001 From: "sonarqube-agent-dev7[bot]" <210668651+sonarqube-agent-dev7[bot]@users.noreply.github.com> Date: Sat, 24 Oct 2026 08:53:03 +0000 Subject: [PATCH] fix: Address 5 SonarQube issues Fixed issues: - AZ-oqu6yhOZFoKAWG_jk for python:S4502 rule - AZ-oqu6yhOZFoKAWG_jl for python:S6965 rule - AZ-oqu6rhOZFoKAWG_jg for python:S112 rule - AZ-oqu6rhOZFoKAWG_ji for python:S8786 rule - AZ-oqu6rhOZFoKAWG_jj for python:S3984 rule Generated by SonarQube Agent (task: feb94dc1-dbf4-4982-9e66-ae6517d2d519) --- pokedex/app.py | 6 +++++- pokedex/helper.py | 6 +++--- pokedex/templates/index.html | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pokedex/app.py b/pokedex/app.py index bddc552..ff85b06 100644 --- a/pokedex/app.py +++ b/pokedex/app.py @@ -1,12 +1,16 @@ import os from flask import Flask, render_template, redirect, url_for, request, g +from flask_wtf.csrf import CSRFProtect from pokedex import helper app = Flask(__name__) app.config["DATABASE"] = "../database.db" +app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY") or os.urandom(32) +csrf = CSRFProtect() +csrf.init_app(app) -@app.route("/") +@app.route("/", methods=["GET"]) def index(): pokemon = [ {"id": id, "pokemon_name": pokemon_name, "image_url": image_url} diff --git a/pokedex/helper.py b/pokedex/helper.py index 4db91b3..191487d 100644 --- a/pokedex/helper.py +++ b/pokedex/helper.py @@ -17,7 +17,7 @@ def register_subscriber(self, email): self.__conn.execute("INSERT into SUBSCRIBERS(email) values (?)", (email,)) self.__conn.commit() except sqlite3.DatabaseError: - raise Exception("Problem with the database!") + raise RuntimeError("Problem with the database!") except sqlite3.IntegrityError: raise ValueError("Email already exists!") @@ -31,8 +31,8 @@ def fetch_all_pokemons(wrapper: ConnectionWrapper): def register_subscriber(wrapper: ConnectionWrapper, email): - pattern = re.compile(r"(.*)@(.*\..*)") + pattern = re.compile(r"([^@]*)@([^.]*\..*)") if not pattern.match(email): - ValueError("Invalid email!") + raise ValueError("Invalid email!") wrapper.register_subscriber(email) pass diff --git a/pokedex/templates/index.html b/pokedex/templates/index.html index 4d0f219..01dc448 100644 --- a/pokedex/templates/index.html +++ b/pokedex/templates/index.html @@ -16,6 +16,7 @@

Pokedex

+