Skip to content

StringUtils.chompLast throws StringIndexOutOfBoundsException when sep is longer than str #400

Description

@elharo

StringUtils.chompLast(@NonNull String str, @NonNull String sep) (line 853) computes str.substring(str.length() - sep.length()) at line 857. If sep is longer than str, the start index is negative, causing StringIndexOutOfBoundsException.

For example: chompLast("x", "ab") throws.

Fix: add a guard returning str when sep.length() > str.length().

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions