Skip to content

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

Closed

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().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions