Description
The internal removesuffix helper claims to backport str.removesuffix, but it returns an empty string when the requested suffix is empty.
Code reference
src/browserbase/_utils/_utils.py:368-375
The implementation executes string[:-len(suffix)]; for an empty suffix this becomes string[:-0], which is string[:0].
Reproduction
from browserbase._utils._utils import removesuffix
print(repr(removesuffix("abc", "")))
print(repr("abc".removesuffix("")))
Actual:
Expected behavior
To match the documented stdlib behavior, an empty suffix should leave the original string unchanged.
Why it matters
This shared helper silently corrupts input for a valid edge case and has no direct test coverage. Even though current in-repo call sites are limited, it is exported through browserbase._utils and may be reused by generated or manual code later. The fix is small (if suffix and string.endswith(suffix): ...) and should include empty-string tests for both prefix/suffix helpers.
Description
The internal
removesuffixhelper claims to backportstr.removesuffix, but it returns an empty string when the requested suffix is empty.Code reference
src/browserbase/_utils/_utils.py:368-375The implementation executes
string[:-len(suffix)]; for an empty suffix this becomesstring[:-0], which isstring[:0].Reproduction
Actual:
Expected behavior
To match the documented stdlib behavior, an empty suffix should leave the original string unchanged.
Why it matters
This shared helper silently corrupts input for a valid edge case and has no direct test coverage. Even though current in-repo call sites are limited, it is exported through
browserbase._utilsand may be reused by generated or manual code later. The fix is small (if suffix and string.endswith(suffix): ...) and should include empty-string tests for both prefix/suffix helpers.