GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — watch: strip watch flags from NODE_OPTIONS in child process by marcopiraccini · Pull Request #62143 · nodejs/node

watch: strip watch flags from NODE_OPTIONS in child process #62143

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.

Sign up for GitHub

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

Merged
nodejs-github-bot merged 6 commits into nodejs:main from marcopiraccini:fix/watch-node-options-infinite-loop
Sep 22, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

watch: strip watch flags from NODE_OPTIONS in child process #62143

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
82f7946
watch: strip watch flags from NODE_OPTIONS in child process
marcopiraccini Mar 7, 2026
cb08852
watch: strip watch flags from NODE_OPTIONS in child process
marcopiraccini Mar 8, 2026
d53aea2
fixup
marcopiraccini Mar 8, 2026
e78ac78
fixup
marcopiraccini Mar 8, 2026
7727a39
fixup after review
marcopiraccini Apr 9, 2026
9def55c
test: skip --watch NODE_OPTIONS test without NODE_OPTIONS support
marcopiraccini May 6, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
Signed-off-by: marcopiraccini <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@marcopiraccini
marcopiraccini committed May 26, 2026
commit d53aea248850218bec787046a1829646da02a2fe

There are no files selected for viewing

9 changes: 3 additions & 6 deletions 9 src/node_options.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2146,8 +2146,7 @@ void GetOptionsAsFlags(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(result);
}

void ParseNodeOptionsEnvVarBinding(
const FunctionCallbackInfo<Value>& args) {
void ParseNodeOptionsEnvVarBinding(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();

Expand Down Expand Up @@ -2189,10 +2188,8 @@ void Initialize(Local<Object> target,
target,
"getNamespaceOptionsInputType",
GetNamespaceOptionsInputType);
SetMethodNoSideEffect(context,
target,
"parseNodeOptionsEnvVar",
ParseNodeOptionsEnvVarBinding);
SetMethodNoSideEffect(
context, target, "parseNodeOptionsEnvVar", ParseNodeOptionsEnvVarBinding);
Local<Object> env_settings = Object::New(isolate);
NODE_DEFINE_CONSTANT(env_settings, kAllowedInEnvvar);
NODE_DEFINE_CONSTANT(env_settings, kDisallowedInEnvvar);
Expand Down
29 changes: 28 additions & 1 deletion 29 test/parallel/test-options-binding.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const common = require('../common');
const assert = require('assert');
const { getOptionValue } = require('internal/options');
const { getOptionValue, parseNodeOptionsEnvVar } = require('internal/options');

Map.prototype.get =
common.mustNotCall('`getOptionValue` must not call user-mutable method');
Expand All @@ -14,3 +14,30 @@ assert.strictEqual(getOptionValue('--nonexistent-option'), undefined);

// Make the test common global leak test happy.
delete Object.prototype['--nonexistent-option'];

// parseNodeOptionsEnvVar tokenizes a NODE_OPTIONS-style string.
assert.deepStrictEqual(
parseNodeOptionsEnvVar('--max-old-space-size=4096 --no-warnings'),
['--max-old-space-size=4096', '--no-warnings']
);

// Quoted strings are unquoted during parsing.
assert.deepStrictEqual(
parseNodeOptionsEnvVar('--require "file with spaces.js"'),
['--require', 'file with spaces.js']
);

// Empty string returns an empty array.
assert.deepStrictEqual(parseNodeOptionsEnvVar(''), []);

// Throws on unterminated string.
assert.throws(
() => parseNodeOptionsEnvVar('--require "unterminated'),
{ name: 'Error', message: /unterminated string/ }
);

// Throws on invalid escape at end of string.
assert.throws(
() => parseNodeOptionsEnvVar('--require "foo\\'),
{ name: 'Error', message: /invalid escape/ }
);
86 changes: 78 additions & 8 deletions 86 test/sequential/test-watch-mode.mjs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -947,14 +947,14 @@ process.on('message', (message) => {
it('should strip all watch flags from NODE_OPTIONS in child process', async () => {
const file = createTmpFile('console.log(process.env.NODE_OPTIONS);');
const nodeOptions = [
'--watch', // bare boolean
'--watch=true', // boolean with =value
'--watch-path=./src', // string with =value
'--watch-path', './test', // String with space-separated value
'--watch-preserve-output', // bare boolean
'--watch-preserve-output=true', // boolean with =value
'--watch-kill-signal=SIGKILL', // string with =value
'--watch-kill-signal', 'SIGINT', // String with space-separated value
'--watch',
'--watch=true',
'--watch-path=./src',
'--watch-path', './test',
'--watch-preserve-output',
'--watch-preserve-output=true',
'--watch-kill-signal=SIGKILL',
'--watch-kill-signal', 'SIGINT',
'--max-old-space-size=4096',
'--no-warnings',
].join(' ');
Expand All @@ -976,4 +976,74 @@ process.on('message', (message) => {
await done();
}
});

it('should not strip --watch when it appears inside a quoted NODE_OPTIONS value', async () => {
const projectDir = tmpdir.resolve('project-watch-quoted');
mkdirSync(projectDir);
const watchDir = path.join(projectDir, 'test for --watch parsing');
mkdirSync(watchDir);
const reqFile = path.join(watchDir, 'req.cjs');
writeFileSync(reqFile, 'globalThis.requiredOk = true;');

const file = createTmpFile('console.log("required:" + !!globalThis.requiredOk);');
const nodeOptions = `--watch --require "${reqFile}"`;
const { done, restart } = runInBackground({
args: ['--watch', file],
options: {
env: { ...process.env, NODE_OPTIONS: nodeOptions },
},
});

try {
const { stdout, stderr } = await restart();

assert.strictEqual(stderr, '');
assert.ok(stdout.some((line) => line.includes('required:true')));
} finally {
await done();
}
});

it('should handle NODE_OPTIONS containing only watch flags', async () => {
const file = createTmpFile('console.log(JSON.stringify(process.env.NODE_OPTIONS));');
const { done, restart } = runInBackground({
args: ['--watch', file],
options: {
env: { ...process.env, NODE_OPTIONS: '--watch' },
},
});

try {
const { stdout, stderr } = await restart();

assert.strictEqual(stderr, '');
assert.ok(stdout.some((line) => line.includes('""')));
} finally {
await done();
}
});

it('should strip multiple --watch-path entries from NODE_OPTIONS', async () => {
const file = createTmpFile('console.log(process.env.NODE_OPTIONS);');
const dirA = tmpdir.resolve('watch-path-a');
const dirB = tmpdir.resolve('watch-path-b');
mkdirSync(dirA, { recursive: true });
mkdirSync(dirB, { recursive: true });
const nodeOptions = `--watch --watch-path=${dirA} --watch-path ${dirB} --no-warnings`;
const { done, restart } = runInBackground({
args: ['--watch', file],
options: {
env: { ...process.env, NODE_OPTIONS: nodeOptions },
},
});

try {
const { stdout, stderr } = await restart();

assert.strictEqual(stderr, '');
assert.ok(stdout.some((line) => line === '--no-warnings'));
} finally {
await done();
}
});
});
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.