sanitize
This commit is contained in:
parent
318079d18c
commit
f7f15fb35a
2 changed files with 22 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
|||
from typing import Optional
|
||||
|
||||
from yt_dlp.utils import sanitize_filename
|
||||
|
||||
from ytdl_sub.script.types.resolvable import AnyArgument
|
||||
from ytdl_sub.script.types.resolvable import Integer
|
||||
from ytdl_sub.script.types.resolvable import Numeric
|
||||
|
|
@ -83,3 +85,11 @@ class StringFunctions:
|
|||
length=length,
|
||||
char=String("0"),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def sanitize(string: String) -> String:
|
||||
"""
|
||||
Returns a sanitized string that is safe to use in file paths (Windows, OSX, Unix).
|
||||
"""
|
||||
# TODO: Move this out of script before making it a separate library
|
||||
return String(sanitize_filename(string.value))
|
||||
|
|
|
|||
|
|
@ -98,3 +98,15 @@ class TestNumericFunctions:
|
|||
def test_pad_zero(self, values: str, expected_output: str):
|
||||
output = single_variable_output(f"{{%pad_zero({values})}}")
|
||||
assert output == expected_output
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"values, expected_output",
|
||||
[
|
||||
("'2012'", "2012"),
|
||||
("'$?ahh'", "$?ahh"),
|
||||
],
|
||||
)
|
||||
def test_sanitize(self, values: str, expected_output: str):
|
||||
# TODO: Move this out once it is its own library
|
||||
output = single_variable_output(f"{{%sanitize({values})}}")
|
||||
assert output == expected_output
|
||||
|
|
|
|||
Loading…
Reference in a new issue