fix(process): normalize scenario replacements literally
capture_process_scenario declares normalization patterns as literal text, but\nreplaceAll expands \$&\, \$\`, and \$1\ in the replacement as a replacement\npattern. A caller normalizing text that contains a dollar sign silently gets\nduplicated, spliced, or dropped content in the recorded Evidence instead of\nthe requested literal replacement.\n\nUse split/join, which is literal on both sides and is already the idiom used\nfor exact-literal scenario rules in browserScenarioNormalization.ts.
This commit is contained in:
@@ -34,8 +34,11 @@ 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.
|
||||
for (const pattern of scenario.normalization.patterns)
|
||||
normalized = normalized.replaceAll(pattern.pattern, pattern.replacement);
|
||||
normalized = normalized.split(pattern.pattern).join(pattern.replacement);
|
||||
return normalized;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user