Skip to content

Commit

Permalink
lib: fix module print timing when specifier includes "
Browse files Browse the repository at this point in the history
PR-URL: nodejs#55150
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
  • Loading branch information
aduh95 authored and louwers committed Nov 2, 2024
1 parent 3d98c60 commit 9371b99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/internal/util/debuglog.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function formatTime(ms) {
}

function safeTraceLabel(label) {
return label.replace(/\\/g, '\\\\');
return label.replace(/\\/g, '\\\\').replaceAll('"', '\\"');
}

/**
Expand Down
11 changes: 10 additions & 1 deletion test/parallel/test-module-print-timing.mjs
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9371b99

Please sign in to comment.