Skip to content

removesuffix helper returns an empty string for an empty suffix #182

Description

@abhinavkr26104

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:

''
'abc'

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions