test_runner: allow special characters in snapshot keys

Fixes: https://github.com/nodejs/node/issues/56836
PR-URL: https://github.com/nodejs/node/pull/57017
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Carlos Espa authored and Michaël Zasso committed 2025-02-25 17:50:59 +01:00
1 parent e3127b89a2
commit 2929fc6449
3 files changed
+53 -1

No files matched your search

+8 -1
View File
@@ -77,7 +77,7 @@ class SnapshotFile {
}
setSnapshot(id, value) {
this.snapshots[templateEscape(id)] = value;
this.snapshots[escapeSnapshotKey(id)] = value;
}
nextId(name) {
@@ -290,6 +290,13 @@ function validateFunctionArray(fns, name) {
}
}
function escapeSnapshotKey(str) {
let result = JSONStringify(str, null, 2).slice(1, -1);
result = StringPrototypeReplaceAll(result, '`', '\\`');
result = StringPrototypeReplaceAll(result, '${', '\\${');
return result;
}
function templateEscape(str) {
let result = String(str);
result = StringPrototypeReplaceAll(result, '\\', '\\\\');