Skip to content

Commit

Permalink
fix crash when NODE_OPTIONS includes --inspect-port (vercel#12555)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Pareja authored and rokinsky committed Jul 11, 2020
1 parent 9baf3b5 commit e926fdd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/server/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export function printAndExit(message: string, code = 1) {
}

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, '')
}
53 changes: 53 additions & 0 deletions test/unit/get-node-options-without-inspect.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* 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')
})
})

0 comments on commit e926fdd

Please sign in to comment.