-
Notifications
You must be signed in to change notification settings - Fork 1
fix lint #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix lint #3
Changes from all commits
e74c2f3
2b54dcf
43809a1
65a6d0b
d4b161a
08b98c5
52d3671
6356db6
22cb5ac
5898dd0
225a775
877692c
5f13d49
bae6b88
4c917ea
c66cf9d
7ed34e7
7edbf27
10f6fd8
eaa3f2d
d2a4359
8a934c9
93e5c56
910140a
c061f9e
3b4a6c7
4a3c908
32ab65d
4991288
9b5893b
8e4efaa
56247d6
2f79ff4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,24 @@ | ||
| from flask import Flask, Response | ||
| from flask import Response | ||
| from typing import Any, Dict | ||
|
|
||
| def process(app, plugin_config: Dict[str, Any]): # Defines the main `process` function taking a Flask app instance and plugin configuration | ||
|
|
||
| def process( | ||
| app, plugin_config: Dict[str, Any] | ||
| ): # Defines the main `process` function taking a Flask app instance and plugin configuration | ||
| # Store plugin configuration (defaults to empty dict) | ||
| app.config['b4uleave'] = plugin_config or {} | ||
| app.config["b4uleave"] = plugin_config or {} | ||
|
|
||
| message = app.config['b4uleave'].get('message', 'Czy na pewno chcesz<br>opuścić naszą stronę?') | ||
| stay = app.config['b4uleave'].get('stay', 'Stay') | ||
| leave = app.config['b4uleave'].get('leave', 'Leave') | ||
| message = app.config["b4uleave"].get( | ||
| "message", "Czy na pewno chcesz<br>opuścić naszą stronę?" | ||
| ) | ||
| stay = app.config["b4uleave"].get("stay", "Stay") | ||
| leave = app.config["b4uleave"].get("leave", "Leave") | ||
|
|
||
|
Comment on lines
+11
to
16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsanitised user-controlled HTML ⇒ reflected-XSS vector.
-import ...
+import html # at top
...
-message = app.config["b4uleave"].get(
- "message", "Czy na pewno chcesz<br>opuścić naszą stronę?"
-)
-stay = app.config["b4uleave"].get("stay", "Stay")
-leave = app.config["b4uleave"].get("leave", "Leave")
+cfg = app.config["b4uleave"]
+message = html.escape(cfg.get("message", "Czy na pewno chcesz<br>opuścić naszą stronę?"), quote=True)
+stay = html.escape(cfg.get("stay", "Stay"), quote=True)
+leave = html.escape(cfg.get("leave", "Leave"), quote=True)If you intentionally allow HTML in Also applies to: 69-73 🤖 Prompt for AI Agents |
||
| @app.after_request # Decorator that registers a function to run after each request is processed | ||
| @app.after_request # Decorator that registers a function to run after each request is processed | ||
| def add_B4ULeave(response: Response) -> Response: | ||
| if 'text/html' in response.headers.get('Content-Type', ''): # Function receives a Response object and returns a modified Response | ||
| if "text/html" in response.headers.get( | ||
| "Content-Type", "" | ||
| ): # Function receives a Response object and returns a modified Response | ||
| html = f""" | ||
| <style> | ||
| #B4ULeave-ModalWindow {{ | ||
|
|
@@ -103,8 +110,10 @@ def add_B4ULeave(response: Response) -> Response: | |
| }}); | ||
| }})(); | ||
| </script>""" | ||
| response.set_data(response.get_data(as_text=True).replace('</body>', html + '</body>')) | ||
| return response | ||
|
|
||
| response.set_data( | ||
| response.get_data(as_text=True).replace("</body>", html + "</body>") | ||
| ) | ||
|
Comment on lines
+115
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion
Consider from bs4 import BeautifulSoup
soup = BeautifulSoup(response.get_data(as_text=True), "html.parser")
if soup.body:
soup.body.append(BeautifulSoup(html, "html.parser"))
response.set_data(str(soup))At minimum, perform a case-insensitive search and fall back gracefully. 🤖 Prompt for AI Agents |
||
| return response | ||
|
|
||
| return app | ||
| return app | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from flask import render_template_string | ||
| from platzky.platzky import create_app as base_create_app | ||
|
|
||
|
|
||
| def create_app(config_path: str): | ||
| # Base app | ||
| app = base_create_app(config_path=config_path) | ||
|
|
||
| @app.route("/") | ||
| def index(): | ||
| return render_template_string( | ||
| """ | ||
| <html> | ||
| <head> | ||
| <title>E2E Test Page</title> | ||
| <style> | ||
| body { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>Welcome to E2E Test</h1> | ||
| <p>This page includes the B4ULeave plugin for testing.</p> | ||
| </body> | ||
| </html> | ||
| """ | ||
| ) | ||
|
|
||
| return app |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| APP_NAME: Bridges in Wroclaw | ||
| SECRET_KEY: SECRET | ||
| BLOG_PREFIX: "/blog" | ||
| DB: | ||
| TYPE: json_file | ||
| PATH: tests/e2e_tests/e2e_test_data.json | ||
|
|
||
| #TODO this should not be necessary argument | ||
| LANGUAGES: | ||
| en: | ||
| name: English | ||
| flag: gb | ||
| country: GB | ||
| pl: | ||
| name: polski | ||
| flag: pl | ||
| country: PL | ||
|
|
||
| FEATURE_FLAGS: | ||
| USE_LAZY_LOADING: True | ||
| SHOW_ACCESSIBILITY_TABLE: True |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| { | ||
| "map": { | ||
| "data": [ | ||
| { | ||
| "name": "Grunwaldzki", | ||
| "position": [ | ||
| 51.1095, | ||
| 17.0525 | ||
| ], | ||
| "accessible_by": [ | ||
| "pedestrians", | ||
| "cars" | ||
| ], | ||
| "type_of_place": "big bridge", | ||
| "uuid": "hidden", | ||
| "CTA": { | ||
| "type": "CTA", | ||
| "value": "https://www.example.com", | ||
| "displayValue": "Visit example.org!" | ||
| } | ||
| }, | ||
| { | ||
| "name": "Zwierzyniecka", | ||
| "position": [ | ||
| 51.10655, | ||
| 17.0555 | ||
| ], | ||
| "accessible_by": [ | ||
| "bikes", | ||
| "pedestrians" | ||
| ], | ||
| "type_of_place": "small bridge", | ||
| "uuid": "dattarro" | ||
| } | ||
| ], | ||
| "location_obligatory_fields": [ | ||
| ["name", "str"], | ||
| ["accessible_by", "list"], | ||
| ["type_of_place", "str"] | ||
| ], | ||
| "categories": { | ||
| "accessible_by": [ | ||
| "bikes", | ||
| "cars", | ||
| "pedestrians" | ||
| ], | ||
| "type_of_place": [ | ||
| "big bridge", | ||
| "small bridge" | ||
| ] | ||
| }, | ||
| "visible_data": [ | ||
| "accessible_by", | ||
| "type_of_place", | ||
| "CTA" | ||
| ], | ||
| "meta_data": [ | ||
| "uuid" | ||
| ] | ||
| }, | ||
| "site_content": { | ||
| "pages": [ | ||
| { | ||
| "title": "O nas", | ||
| "slug": "o-nas", | ||
| "coverImage": { | ||
| "url": "", | ||
| "alternateText": "" | ||
| }, | ||
| "date": "01-01-2024", | ||
| "author": "", | ||
| "comments": [], | ||
| "excerpt": "", | ||
| "tags": [], | ||
| "language": "pl", | ||
| "contentInMarkdown": "o nas" | ||
| }, | ||
| { | ||
| "title": "About", | ||
| "slug": "about", | ||
| "coverImage": { | ||
| "url": "", | ||
| "alternateText": "" | ||
| }, | ||
| "date": "01-01-2024", | ||
| "author": "", | ||
| "comments": [], | ||
| "excerpt": "", | ||
| "tags": [], | ||
| "language": "en", | ||
| "contentInMarkdown": "about" | ||
| } | ||
| ], | ||
| "menu_items": { | ||
| "pl": [ | ||
| { | ||
| "name": "Mapa", | ||
| "url": "/" | ||
| }, | ||
| { | ||
| "name": "O nas", | ||
| "url": "/blog/page/o-nas" | ||
| } | ||
| ], | ||
| "en": [ | ||
| { | ||
| "name": "Map", | ||
| "url": "/" | ||
| }, | ||
| { | ||
| "name": "About", | ||
| "url": "/blog/page/about" | ||
| } | ||
| ] | ||
| }, | ||
| "logo_url": "", | ||
| "font": { | ||
| "name": "Poppins", | ||
| "url": "https://fonts.googleapis.com/css2?family=Poppins" | ||
| }, | ||
| "primary_color": "#FFFFFF", | ||
| "secondary_color": "#245466", | ||
| "left_bar_width": "300px" | ||
| }, | ||
| "plugins": [ | ||
| { | ||
| "name": "b4uleave", | ||
| "config": { | ||
| "message": "Your custom message goes here" | ||
| } | ||
| } | ||
| ] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Harden e2e step: avoid reloader, wait for readiness, and ensure clean teardown
Current approach uses --debug (spawns a reloader) and a fixed sleep which can flake. Start a single process, wait until it’s responsive, and always kill it on exit.
Apply:
Optional: upload flask.log on failure to aid debugging.
📝 Committable suggestion
🤖 Prompt for AI Agents