From 030caeea70d39f607711b5d0bcdc226e3bdfe804 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 28 Sep 2024 15:14:13 +0200 Subject: [PATCH] lib: fix module print timing when specifier includes `"` --- lib/internal/util/debuglog.js | 2 +- test/parallel/test-module-print-timing.mjs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js index 0ffb79041641ac..271c9d1497d88f 100644 --- a/lib/internal/util/debuglog.js +++ b/lib/internal/util/debuglog.js @@ -173,7 +173,7 @@ function formatTime(ms) { } function safeTraceLabel(label) { - return label.replace(/\\/g, '\\\\'); + return label.replace(/\\/g, '\\\\').replaceAll('"', '\\"'); } /** diff --git a/test/parallel/test-module-print-timing.mjs b/test/parallel/test-module-print-timing.mjs index 01f715482e7ccd..b9ee92a6dd3f3b 100644 --- a/test/parallel/test-module-print-timing.mjs +++ b/test/parallel/test-module-print-timing.mjs @@ -1,5 +1,6 @@ -import '../common/index.mjs'; +import { isWindows } from '../common/index.mjs'; import assert from 'node:assert'; +import { writeFileSync } from 'node:fs'; import { readFile } from 'node:fs/promises'; import { it } from 'node:test'; import tmpdir from '../common/tmpdir.js'; @@ -113,11 +114,19 @@ it('should support enable tracing dynamically', async () => { const outputFile = tmpdir.resolve('output-dynamic-trace.log'); + let requireFileWithDoubleQuote = '' + if (!isWindows) { + // Double quotes are not valid char for a path on Windows. + const fileWithDoubleQuote = tmpdir.resolve('filename-with-"double"-quotes.cjs'); + writeFileSync(fileWithDoubleQuote, ';\n'); + requireFileWithDoubleQuote = `require(${JSON.stringify(fileWithDoubleQuote)});` + } const jsScript = ` const traceEvents = require("trace_events"); const tracing = traceEvents.createTracing({ categories: ["node.module_timer"] }); tracing.enable(); + ${requireFileWithDoubleQuote} require("http"); tracing.disable();