fix(process)!: version literal scenario replacement semantics

Keep caller-selected replacement text literal with a callback, preserving
empty-search positions instead of changing their split/join behavior.
Commit the replacement interpretation for captures using custom patterns so
legacy records cannot report this producer correction as a target change.

BREAKING CHANGE: Captures with custom normalization patterns use
literal-replacements-v1 and cannot be compared with legacy unversioned
pattern captures. Capture both sides with the same replacement semantics;
legacy captures remain readable and captures without patterns are unaffected.
This commit is contained in:
N0zoM1z0
2026-10-10 16:57:06 +08:00
committed by Ysopwnable
parent f51503ef1c
commit 2b6f14f528
5 changed files with 121 additions and 17 deletions
+6 -4
View File
@@ -34,11 +34,13 @@ export const normalizeProcessText = (
normalized = normalizePortTokens(normalized);
if (scenario.normalization.pids)
normalized = normalizePidTokens(normalized, [pid]);
// Scenario replacements are literal text, so `$&`, `` $` ``, and `$1` must
// reach the captured output verbatim instead of expanding as a replacement
// pattern. split/join is literal on both sides.
// A callback keeps replacement text literal while preserving replaceAll's
// empty-pattern boundaries, which the process scenario contract permits.
for (const pattern of scenario.normalization.patterns)
normalized = normalized.split(pattern.pattern).join(pattern.replacement);
normalized = normalized.replaceAll(
pattern.pattern,
() => pattern.replacement,
);
return normalized;
};