From 78f421de886b80be099e597845d8b3235200fdfa Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 8 Oct 2024 17:59:37 +0100 Subject: [PATCH] lib: fix module print timing when specifier includes `"` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/55150 Reviewed-By: Vinícius Lourenço Claro Cardoso --- 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 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();