diff --git a/emmett/__version__.py b/emmett/__version__.py index 7a2056f5..667b52f9 100644 --- a/emmett/__version__.py +++ b/emmett/__version__.py @@ -1 +1 @@ -__version__ = "2.5.1" +__version__ = "2.5.2" diff --git a/emmett/asgi/handlers.py b/emmett/asgi/handlers.py index 0a9a9425..2c93455a 100644 --- a/emmett/asgi/handlers.py +++ b/emmett/asgi/handlers.py @@ -250,13 +250,15 @@ def _static_lang_matcher( def _static_nolang_matcher( self, path: str ) -> Tuple[Optional[str], Optional[str]]: - if path.startswith('/static'): + if path.startswith('/static/'): mname, version, file_name = REGEX_STATIC.match(path).group('m', 'v', 'f') if mname: mod = self.app._modules.get(mname[2:-3]) static_file = os.path.join(mod._static_path, file_name) if mod else None - else: + elif file_name: static_file = os.path.join(self.app.static_path, file_name) + else: + static_file = None return static_file, version return None, None @@ -288,7 +290,7 @@ def _static_handler( #: handle internal assets if path.startswith('/__emmett__'): file_name = path[12:] - if file_name.endswith(".html"): + if not file_name or file_name.endswith(".html"): return self._http_response(404) pkg = None if '/' in file_name: diff --git a/emmett/http.py b/emmett/http.py index bdc4b5e7..ee21ab3a 100644 --- a/emmett/http.py +++ b/emmett/http.py @@ -244,12 +244,12 @@ def rsgi(self, protocol: HTTPProtocol): try: stat_data = os.stat(self.file_path) if not stat.S_ISREG(stat_data.st_mode): - return HTTP(403).rsgi() + return HTTP(403).rsgi(protocol) self._headers.update(self._get_stat_headers(stat_data)) except IOError as e: if e.errno == errno.EACCES: - return HTTP(403).rsgi() - return HTTP(404).rsgi() + return HTTP(403).rsgi(protocol) + return HTTP(404).rsgi(protocol) protocol.response_file( self.status_code, diff --git a/emmett/rsgi/handlers.py b/emmett/rsgi/handlers.py index 80966067..433b0d8c 100644 --- a/emmett/rsgi/handlers.py +++ b/emmett/rsgi/handlers.py @@ -144,13 +144,15 @@ def _static_lang_matcher( def _static_nolang_matcher( self, path: str ) -> Tuple[Optional[str], Optional[str]]: - if path.startswith('/static'): + if path.startswith('/static/'): mname, version, file_name = REGEX_STATIC.match(path).group('m', 'v', 'f') if mname: mod = self.app._modules.get(mname[2:-3]) static_file = os.path.join(mod._static_path, file_name) if mod else None - else: + elif file_name: static_file = os.path.join(self.app.static_path, file_name) + else: + static_file = None return static_file, version return None, None @@ -166,8 +168,11 @@ def _static_handler( #: handle internal assets if path.startswith('/__emmett__'): file_name = path[12:] + if not file_name: + return self._http_response(404) static_file = os.path.join( - os.path.dirname(__file__), '..', 'assets', file_name) + os.path.dirname(__file__), '..', 'assets', file_name + ) if os.path.splitext(static_file)[1] == 'html': return self._http_response(404) return self._static_response(static_file) diff --git a/pyproject.toml b/pyproject.toml index b536da3d..4ba696bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "emmett" -version = "2.5.1" +version = "2.5.2" description = "The web framework for inventors" authors = ["Giovanni Barillari "] license = "BSD-3-Clause" @@ -43,7 +43,7 @@ emmett = "emmett.cli:main" [tool.poetry.dependencies] python = "^3.8" click = ">=6.0" -granian = "~0.4.0" +granian = "~0.4.2" emmett-crypto = "~0.3" pendulum = "~2.1.2" pyDAL = "17.3"