@@ -108,9 +108,18 @@ function transformPath(dirname, replacement) {
108108 // On Windows, paths are case-insensitive, so we need to use case-insensitive
109109 // regex replacement to handle cases where the drive letter case differs.
110110 const flags = common . isWindows ? 'gi' : 'g' ;
111- const urlEncodedRegex = new RegExp ( RegExp . escape ( urlEncoded ) , flags ) ;
112- const dirnameRegex = new RegExp ( RegExp . escape ( dirname ) , flags ) ;
113- const winPathRegex = new RegExp ( RegExp . escape ( winPath ) , flags ) ;
111+
112+ // Escape and add word boundaries to prevent partial matches
113+ // (e.g., /node shouldn't match /node_modules or nodejs.org)
114+ const escapedUrlEncoded = RegExp . escape ( urlEncoded ) ;
115+ const escapedDirname = RegExp . escape ( dirname ) ;
116+ const escapedWinPath = RegExp . escape ( winPath ) ;
117+
118+ // Use negative lookahead to prevent matching if followed by alphanumeric, underscore, or slash
119+ const urlEncodedRegex = new RegExp ( escapedUrlEncoded + '(?![\\w/])' , flags ) ;
120+ const dirnameRegex = new RegExp ( escapedDirname + '(?![\\w/])' , flags ) ;
121+ const winPathRegex = new RegExp ( escapedWinPath + '(?![\\w/])' , flags ) ;
122+
114123 return ( str ) => {
115124 return str . replaceAll ( '\\\'' , "'" )
116125 // Replace fileUrl first as `winPath` could be a substring of the fileUrl.
0 commit comments