0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00

lib: fix module print timing when specifier includes "

PR-URL: https://github.com/nodejs/node/pull/55150
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
This commit is contained in:
Antoine du Hamel 2024-10-08 17:59:37 +01:00 committed by GitHub
parent accb239272
commit 78f421de88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -173,7 +173,7 @@ function formatTime(ms) {
}
function safeTraceLabel(label) {
return label.replace(/\\/g, '\\\\');
return label.replace(/\\/g, '\\\\').replaceAll('"', '\\"');
}
/**

View File

@ -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();