Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/node_config_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ constexpr std::string_view kConfigFileFlag = "--experimental-config-file";
constexpr std::string_view kDefaultConfigFileFlag =
"--experimental-default-config-file";
constexpr std::string_view kDefaultConfigFileName = "node.config.json";
constexpr std::string_view kSchemaField = "$schema";

inline bool HasEqualsPrefix(std::string_view arg, std::string_view flag) {
return arg.size() > flag.size() && arg.starts_with(flag) &&
Expand Down Expand Up @@ -290,10 +291,14 @@ ParseResult ConfigReader::ParseConfig(const std::string_view& config_path) {
return ParseResult::InvalidContent;
}

if (namespace_name == kSchemaField) {
continue;
}

// Check if this field is a valid namespace
if (!valid_namespaces.contains(namespace_name)) {
// If not, skip it
continue;
FPrintF(stderr, "Unknown namespace %s\n", namespace_name);
return ParseResult::InvalidContent;
}

// List of implicit namespace flags
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/rc/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://nodejs.org/dist/vX.Y.Z/docs/node-config-schema.json",
"nodeOptions": {
"max-http-header-size": 10
}
}
16 changes: 14 additions & 2 deletions test/parallel/test-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,26 @@ describe('namespace-scoped options', () => {
assert.strictEqual(result.code, 9);
});

it('should not throw an error when a namespace is not recognised', async () => {
it('should throw an error when a namespace is not recognised', async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
`--experimental-config-file=${fixtures.path('rc/unknown-namespace.json')}`,
'-p', '"Hello, World!"',
]);
assert.match(result.stderr, /Unknown namespace an-invalid-namespace/);
assert.match(result.stderr, /unknown-namespace\.json: invalid content/);
assert.strictEqual(result.stdout, '');
assert.strictEqual(result.code, 9);
});

it('should allow the $schema field', async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
`--experimental-config-file=${fixtures.path('rc/schema.json')}`,
'-p', 'http.maxHeaderSize',
]);
assert.strictEqual(result.stderr, '');
assert.strictEqual(result.stdout, 'Hello, World!\n');
assert.strictEqual(result.stdout, '10\n');
assert.strictEqual(result.code, 0);
});

Expand Down
Loading