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.
Problem
replaceLastOccurrence()assumes the search fragment exists in the source string.When it does not,
lastIndexOf()returns-1and the current implementation can return a corrupted string.Impact
Expected behavior
If the search fragment is not found, the function should return the original string unchanged.