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
2 changes: 1 addition & 1 deletion src/browserbase/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def removesuffix(string: str, suffix: str) -> str:

Backport of `str.removesuffix` for Python < 3.9
"""
if string.endswith(suffix):
if suffix and string.endswith(suffix):
return string[: -len(suffix)]
return string

Expand Down
31 changes: 31 additions & 0 deletions tests/test_utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import annotations

import pytest

from browserbase._utils import removeprefix, removesuffix


@pytest.mark.parametrize(
("string", "prefix"),
[
("browserbase", "browser"),
("browserbase", "base"),
("browserbase", ""),
("", ""),
],
)
def test_removeprefix_matches_stdlib(string: str, prefix: str) -> None:
assert removeprefix(string, prefix) == string.removeprefix(prefix)


@pytest.mark.parametrize(
("string", "suffix"),
[
("browserbase", "base"),
("browserbase", "browser"),
("browserbase", ""),
("", ""),
],
)
def test_removesuffix_matches_stdlib(string: str, suffix: str) -> None:
assert removesuffix(string, suffix) == string.removesuffix(suffix)