Skip to content

Preserve suffix after a replacement at the range boundary - #151

Open
dajiaohuang wants to merge 1 commit into
Cysharp:masterfrom
dajiaohuang:fix/zstring-replace-suffix-20261015
Open

dajiaohuang wants to merge 1 commit into
Cysharp:masterfrom
dajiaohuang:fix/zstring-replace-suffix-20261015

Conversation

@dajiaohuang

Copy link
Copy Markdown

Problem

A supported ranged string replacement can silently discard text after the replacement range when the last match ends exactly at that range's boundary:

using var sb = ZString.CreateStringBuilder();
sb.Append("abcTAIL");
sb.Replace("bc", "X", 1, 2);
// Actual: "aX"; StringBuilder result: "aXTAIL"

The suffix was copied only when another loop iteration found no match. If the final match consumed the replacement range, that iteration never occurred.

Change

Track the consumed source position and copy the unconsumed suffix after the replacement loop. This preserves the suffix both when the loop exits at a match boundary and when it finds no further match. Add comparison cases for removal, expansion, repeated matches, a remaining in-range character, and a match at the end of the builder. Unity source is updated through the existing netstandard2.1 post-build copy target.

Validation

  • 3 new cases fail at master b9c1d8a; the other 3 are passing controls.
  • All 6 pass with the fix; full maintained test project: 153 passed.
  • Release solution build passes (existing warnings remain).
  • Tests use DOTNET_ROLL_FORWARD=Major because .NET 7 runtime is unavailable locally. No Unity editor/TMP/IL2CPP execution.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant