Use importlib.metadata.version('flask') to detect Flask version

This commit is contained in:
Miguel Jacq 2025-03-06 16:05:48 +11:00
parent 303c83604c
commit ea34d32406
No known key found for this signature in database
GPG Key ID: 59B3F0C24135C6A9

View File

@ -17,6 +17,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import importlib
import logging
import mimetypes
import os
@ -34,7 +35,6 @@ from flask import (
abort,
make_response,
send_file,
__version__ as flask_version,
)
from flask_compress import Compress
from flask_socketio import SocketIO
@ -138,6 +138,7 @@ class Web:
# by default. To prevent content injection through template variables in
# earlier versions of Flask, we force autoescaping in the Jinja2 template
# engine if we detect a Flask version with insecure default behavior.
flask_version = importlib.metadata.version("flask")
if Version(flask_version) < Version("0.11"):
# Monkey-patch in the fix from https://github.com/pallets/flask/commit/99c99c4c16b1327288fd76c44bc8635a1de452bc
Flask.select_jinja_autoescape = self._safe_select_jinja_autoescape