Skip to content

Avoid corrupting strings when replaceLastOccurrence does not find the search fragment #11

Description

@javihgil

Problem

replaceLastOccurrence() assumes the search fragment exists in the source string.

When it does not, lastIndexOf() returns -1 and the current implementation can return a corrupted string.

Impact

  • index updates can become fragile in unexpected HTML structures
  • id or full-name rewriting may produce broken markup instead of leaving the string unchanged

Expected behavior

If the search fragment is not found, the function should return the original string unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions