Skip to content

Commit

Permalink
Add Flask 2.1.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyespo committed Mar 29, 2022
1 parent 575498f commit b915078
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
27 changes: 27 additions & 0 deletions grip/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# TODO: Use Werkzeug's directly after dropping support for older Flask versions
try:
# Use older Flask implementation directly to ensure backwards compatibility
from flask import safe_join
except ImportError:
import werkzeug.utils
from werkzeug.exceptions import NotFound

# Use port of Flask 2.0 safe_join to match behavior
def safe_join(directory, *pathnames):
"""Safely join zero or more untrusted path components to a base
directory to avoid escaping the base directory.
:param directory: The trusted base directory.
:param pathnames: The untrusted path components relative to the
base directory.
:return: A safe path.
"""
path = werkzeug.utils.safe_join(directory, *pathnames)

if path is None:
raise NotFound()

return path


__all__ = ['safe_join']
3 changes: 2 additions & 1 deletion grip/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from urllib.parse import urljoin

import requests
from werkzeug.utils import safe_join

from ._compat import safe_join

from .constants import (
STYLE_URLS_SOURCE, STYLE_URLS_RES, STYLE_ASSET_URLS_RE,
Expand Down
2 changes: 1 addition & 1 deletion grip/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
from abc import ABCMeta, abstractmethod

from werkzeug.utils import safe_join
from ._compat import safe_join

from .constants import DEFAULT_FILENAMES, DEFAULT_FILENAME
from .exceptions import ReadmeNotFoundError
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Markdown>=2.5.1
path-and-address>=2.0.1
Pygments>=1.6
requests>=2.4.1
Werkzeug>=2.1.0
Werkzeug>=0.7

0 comments on commit b915078

Please sign in to comment.
  NODES
COMMUNITY 1
Note 1
Project 3
todo 1
USERS 1