Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure null bytes in resolved path are handled #30313

Merged
merged 1 commit into from Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -432,7 +432,9 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
// package.json could be needed for resolving e.g. stylis
// stylis/package.json -> stylis/dist/umd/package.json
if (result.includes('node_modules')) {
let requestPath = result.replace(/\\/g, '/')
let requestPath = result
.replace(/\\/g, '/')
.replace(/\0/g, '')

if (
!nodePath.isAbsolute(request) &&
Expand All @@ -444,7 +446,9 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
request.substr(getPkgName(request)?.length || 0) +
nodePath.sep +
'package.json'
).replace(/\\/g, '/')
)
.replace(/\\/g, '/')
.replace(/\0/g, '')
}

const rootSeparatorIndex = requestPath.indexOf('/')
Expand Down Expand Up @@ -524,7 +528,7 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
if (!res) {
throw new Error(`failed to resolve ${request} from ${parent}`)
}
return res
return res.replace(/\0/g, '')
}

this.tapfinishModules(
Expand Down
4 changes: 4 additions & 0 deletions test/integration/production/pages/index.js
@@ -1,6 +1,10 @@
import Link from 'next/link'

if (typeof window === 'undefined') {
try {
let file = 'clear.js'
require('es5-ext/array/#/' + file)
} catch (_) {}
import('nanoid').then((mod) => console.log(mod.nanoid()))
}

Expand Down
12 changes: 7 additions & 5 deletions test/integration/production/test/index.test.js
Expand Up @@ -123,7 +123,7 @@ describe('Production Usage', () => {
/node_modules\/react\/package\.json/,
/node_modules\/react\/cjs\/react\.production\.min\.js/,
],
notTests: [/node_modules\/react\/cjs\/react\.development\.js/],
notTests: [/node_modules\/react\/cjs\/react\.development\.js/, /\0/],
},
{
page: '/client-error',
Expand All @@ -139,7 +139,7 @@ describe('Production Usage', () => {
/next\/dist\/pages\/_error\.js/,
/next\/error\.js/,
],
notTests: [/node_modules\/react\/cjs\/react\.development\.js/],
notTests: [/node_modules\/react\/cjs\/react\.development\.js/, /\0/],
},
{
page: '/dynamic',
Expand All @@ -153,7 +153,7 @@ describe('Production Usage', () => {
/next\/dist\/client\/link\.js/,
/next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/,
],
notTests: [/node_modules\/react\/cjs\/react\.development\.js/],
notTests: [/node_modules\/react\/cjs\/react\.development\.js/, /\0/],
},
{
page: '/index',
Expand All @@ -168,12 +168,14 @@ describe('Production Usage', () => {
/next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/,
/node_modules\/nanoid\/index\.js/,
/node_modules\/nanoid\/url-alphabet\/index\.js/,
/node_modules\/es5-ext\/array\/#\/clear\.js/,
],
notTests: [
/node_modules\/react\/cjs\/react\.development\.js/,
/node_modules\/nanoid\/index\.cjs/,
/next\/dist\/pages\/_error\.js/,
/next\/error\.js/,
/\0/,
],
},
{
Expand All @@ -188,7 +190,7 @@ describe('Production Usage', () => {
/next\/dist\/client\/router\.js/,
/next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/,
],
notTests: [/node_modules\/react\/cjs\/react\.development\.js/],
notTests: [/node_modules\/react\/cjs\/react\.development\.js/, /\0/],
},
{
page: '/next-import',
Expand All @@ -202,7 +204,7 @@ describe('Production Usage', () => {
/next\/dist\/client\/link\.js/,
/next\/dist\/shared\/lib\/router\/utils\/resolve-rewrites\.js/,
],
notTests: [/next\/dist\/server\/next\.js/, /next\/dist\/bin/],
notTests: [/next\/dist\/server\/next\.js/, /next\/dist\/bin/, /\0/],
},
]

Expand Down