diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js index 0ffb7904164..271c9d1497d 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 01f715482e7..eb957742b2e 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();