Skip to content

Commit

Permalink
lib: fix module print timing when specifier includes "
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Sep 28, 2024
1 parent 23743f6 commit 030caee
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 = ''

Check failure on line 117 in test/parallel/test-module-print-timing.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
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)});`

Check failure on line 122 in test/parallel/test-module-print-timing.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
}
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 030caee

Please sign in to comment.