Fix to prevent applying HTML replacements past the end of a substring.