mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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:
1 parent
e3127b89a2
commit
2929fc6449
3 files changed
+53
-1
No files matched your search
@@ -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, '\\', '\\\\');
|
||||
|
||||
Reference in new issue
Block a user