mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Clean up deprecated sanitize_filename and sanitize_path (#60859)
This commit is contained in:
parent
9e96f3e227
commit
3c66706a49
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user