From 3c66706a49e0d0a6147f352b6b8d425d7b874fae Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 2 Dec 2021 21:35:11 +0100 Subject: [PATCH] Clean up deprecated sanitize_filename and sanitize_path (#60859) --- homeassistant/util/__init__.py | 33 --------------------------------- tests/util/test_init.py | 16 ---------------- 2 files changed, 49 deletions(-) diff --git a/homeassistant/util/__init__.py b/homeassistant/util/__init__.py index b71fd8fa5e4..637b98a1a75 100644 --- a/homeassistant/util/__init__.py +++ b/homeassistant/util/__init__.py @@ -15,7 +15,6 @@ from typing import Any, TypeVar import slugify as unicode_slug -from ..helpers.deprecation import deprecated_function from .dt import as_local, utcnow T = TypeVar("T") @@ -46,38 +45,6 @@ def raise_if_invalid_path(path: str) -> None: raise ValueError(f"{path} is not a safe path") -@deprecated_function(replacement="raise_if_invalid_filename") -def sanitize_filename(filename: str) -> str: - """Check if a filename is safe. - - Only to be used to compare to original filename to check if changed. - If result changed, the given path is not safe and should not be used, - raise an error. - - DEPRECATED. - """ - # Backwards compatible fix for misuse of method - if RE_SANITIZE_FILENAME.sub("", filename) != filename: - return "" - return filename - - -@deprecated_function(replacement="raise_if_invalid_path") -def sanitize_path(path: str) -> str: - """Check if a path is safe. - - Only to be used to compare to original path to check if changed. - If result changed, the given path is not safe and should not be used, - raise an error. - - DEPRECATED. - """ - # Backwards compatible fix for misuse of method - if RE_SANITIZE_PATH.sub("", path) != path: - return "" - return path - - def slugify(text: str | None, *, separator: str = "_") -> str: """Slugify a given text.""" if text == "" or text is None: diff --git a/tests/util/test_init.py b/tests/util/test_init.py index b2ede0c881b..e80c3fd6989 100644 --- a/tests/util/test_init.py +++ b/tests/util/test_init.py @@ -8,22 +8,6 @@ from homeassistant import util import homeassistant.util.dt as dt_util -def test_sanitize_filename(): - """Test sanitize_filename.""" - assert util.sanitize_filename("test") == "test" - assert util.sanitize_filename("/test") == "" - assert util.sanitize_filename("..test") == "" - assert util.sanitize_filename("\\test") == "" - assert util.sanitize_filename("\\../test") == "" - - -def test_sanitize_path(): - """Test sanitize_path.""" - assert util.sanitize_path("test/path") == "test/path" - assert util.sanitize_path("~test/path") == "" - assert util.sanitize_path("~/../test/path") == "" - - def test_raise_if_invalid_filename(): """Test raise_if_invalid_filename.""" assert util.raise_if_invalid_filename("test") is None