Skip to content

Commit 079fbca

Browse files
committed
src: iterate on import attributes array correctly
The array's length is supposed to be a multiple of two. Fixes: nodejs#50700
1 parent 0304da2 commit 079fbca

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/module_wrap.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ static Local<Object> createImportAttributesContainer(
253253
Environment* env, Isolate* isolate, Local<FixedArray> raw_attributes) {
254254
Local<Object> attributes =
255255
Object::New(isolate, v8::Null(env->isolate()), nullptr, nullptr, 0);
256-
for (int i = 0; i < raw_attributes->Length(); i += 3) {
256+
CHECK_EQ(raw_attributes->Length() % 2, 0);
257+
for (int i = 0; i < raw_attributes->Length(); i += 2) {
257258
attributes
258259
->Set(env->context(),
259260
raw_attributes->Get(env->context(), i).As<String>(),

test/es-module/test-esm-import-attributes-errors.js

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ async function test() {
2626
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
2727
);
2828

29+
await rejects(
30+
import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }),
31+
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
32+
);
33+
2934
await rejects(
3035
import(jsModuleDataUrl, { with: { type: 'unsupported' } }),
3136
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }

test/es-module/test-esm-import-attributes-errors.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ await rejects(
2121
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
2222
);
2323

24+
await rejects(
25+
import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }),
26+
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
27+
);
28+
2429
await rejects(
2530
import(import.meta.url, { with: { type: 'unsupported' } }),
2631
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }

0 commit comments

Comments
 (0)