Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions test/common/assertSnapshot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
'use strict';
const common = require('.');
const path = require('node:path');
const test = require('node:test');
Expand Down Expand Up @@ -33,8 +33,15 @@ function replaceWindowsPaths(str) {

function transformProjectRoot(replacement = '') {
const projectRoot = path.resolve(__dirname, '../..');
// Fix for issue #61303: Use a regex to only match projectRoot when it appears
// as an actual path prefix, not as a substring within URLs (like nodejs.org)
// or other paths (like /node_modules) when CWD happens to be /node.
// Match projectRoot followed by: path separator, colon (for line numbers),
// whitespace, or end of string.
const escapedRoot = projectRoot.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const projectRootRegex = new RegExp(escapedRoot + '(?=[/\\\\:\\s]|$)', 'g');
return (str) => {
return str.replaceAll('\\\'', "'").replaceAll(projectRoot, replacement);
return str.replaceAll('\\\'', "'").replace(projectRootRegex, replacement);
};
}

Expand Down