Unverified Commit 5af38f17 authored by Mario Pareja's avatar Mario Pareja Committed by GitHub

fix crash when NODE_OPTIONS includes --inspect-port (#12555)

parent c334a275
...@@ -10,6 +10,6 @@ export function printAndExit(message: string, code = 1) { ...@@ -10,6 +10,6 @@ export function printAndExit(message: string, code = 1) {
} }
export function getNodeOptionsWithoutInspect() { export function getNodeOptionsWithoutInspect() {
const NODE_INSPECT_RE = /--inspect(-brk)?(=\S+)? ?/ const NODE_INSPECT_RE = /--inspect(-brk)?(=\S+)?( |$)/
return (process.env.NODE_OPTIONS || '').replace(NODE_INSPECT_RE, '') return (process.env.NODE_OPTIONS || '').replace(NODE_INSPECT_RE, '')
} }
/* eslint-env jest */
import { getNodeOptionsWithoutInspect } from 'next/dist/server/lib/utils'
const originalNodeOptions = process.env.NODE_OPTIONS
afterAll(() => {
process.env.NODE_OPTIONS = originalNodeOptions
})
describe('getNodeOptionsWithoutInspect', () => {
it('removes --inspect option', () => {
process.env.NODE_OPTIONS = '--other --inspect --additional'
const result = getNodeOptionsWithoutInspect()
expect(result).toBe('--other --additional')
})
it('removes --inspect option at end of line', () => {
process.env.NODE_OPTIONS = '--other --inspect'
const result = getNodeOptionsWithoutInspect()
expect(result).toBe('--other ')
})
it('removes --inspect option with parameters', () => {
process.env.NODE_OPTIONS = '--other --inspect=0.0.0.0:1234 --additional'
const result = getNodeOptionsWithoutInspect()
expect(result).toBe('--other --additional')
})
it('removes --inspect-brk option', () => {
process.env.NODE_OPTIONS = '--other --inspect-brk --additional'
const result = getNodeOptionsWithoutInspect()
expect(result).toBe('--other --additional')
})
it('removes --inspect-brk option with parameters', () => {
process.env.NODE_OPTIONS = '--other --inspect-brk=0.0.0.0:1234 --additional'
const result = getNodeOptionsWithoutInspect()
expect(result).toBe('--other --additional')
})
it('ignores unrelated options starting with --inspect-', () => {
process.env.NODE_OPTIONS =
'--other --inspect-port=0.0.0.0:1234 --additional'
const result = getNodeOptionsWithoutInspect()
expect(result).toBe('--other --inspect-port=0.0.0.0:1234 --additional')
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment