Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/pendulum/locales/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def load(cls, locale: str | Locale) -> Locale:
if locale in cls._cache:
return cls._cache[locale]

# A locale is a package name, not a path
if not re.fullmatch("[a-z]+(_[a-z0-9]+)*", locale):
raise ValueError(f"Locale [{locale}] does not exist.")

# Checking locale existence
actual_locale = locale
locale_path = cast(Path, resources.files(__package__).joinpath(actual_locale))
Expand Down
6 changes: 6 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ def test_set_locale_malformed_locale(locale: str) -> None:
pendulum.set_locale("en")


@pytest.mark.parametrize("locale", ["..", "../tz", "en/../en"])
def test_set_locale_path_is_invalid(locale: str) -> None:
with pytest.raises(ValueError):
pendulum.set_locale(locale)


def test_week_starts_at() -> None:
pendulum.week_starts_at(pendulum.SATURDAY)

Expand Down