Skip to content

Commit 08b5e6c

Browse files
committed
lib: fix module print timing when specifier includes "
PR-URL: #55150 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
1 parent 85b7659 commit 08b5e6c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/internal/util/debuglog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function formatTime(ms) {
173173
}
174174

175175
function safeTraceLabel(label) {
176-
return label.replace(/\\/g, '\\\\');
176+
return label.replace(/\\/g, '\\\\').replaceAll('"', '\\"');
177177
}
178178

179179
/**

test/parallel/test-module-print-timing.mjs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import '../common/index.mjs';
1+
import { isWindows } from '../common/index.mjs';
22
import assert from 'node:assert';
3+
import { writeFileSync } from 'node:fs';
34
import { readFile } from 'node:fs/promises';
45
import { it } from 'node:test';
56
import tmpdir from '../common/tmpdir.js';
@@ -113,11 +114,19 @@ it('should support enable tracing dynamically', async () => {
113114

114115

115116
const outputFile = tmpdir.resolve('output-dynamic-trace.log');
117+
let requireFileWithDoubleQuote = '';
118+
if (!isWindows) {
119+
// Double quotes are not valid char for a path on Windows.
120+
const fileWithDoubleQuote = tmpdir.resolve('filename-with-"double"-quotes.cjs');
121+
writeFileSync(fileWithDoubleQuote, ';\n');
122+
requireFileWithDoubleQuote = `require(${JSON.stringify(fileWithDoubleQuote)});`;
123+
}
116124
const jsScript = `
117125
const traceEvents = require("trace_events");
118126
const tracing = traceEvents.createTracing({ categories: ["node.module_timer"] });
119127
120128
tracing.enable();
129+
${requireFileWithDoubleQuote}
121130
require("http");
122131
tracing.disable();
123132

0 commit comments

Comments
 (0)