Skip to content

Guard required_ext access in validateFileResourceUploads (fixes TypeError for optional-only types)#2561

Open
Valyrian-Code wants to merge 2 commits into
GeoNode:masterfrom
Valyrian-Code:fix/upload-required-ext-guard
Open

Guard required_ext access in validateFileResourceUploads (fixes TypeError for optional-only types)#2561
Valyrian-Code wants to merge 2 commits into
GeoNode:masterfrom
Valyrian-Code:fix/upload-required-ext-guard

Conversation

@Valyrian-Code

Copy link
Copy Markdown

Problem

validateFileResourceUploads dereferences currentSupportedType.required_ext directly:

const allUploadsAreOptional = upload.ext.every(ext =>
    (currentSupportedType.optional_ext || []).includes(ext) &&
    !currentSupportedType.required_ext.includes(ext)          // <-- no guard
);
const missingExtensions = allUploadsAreOptional
    ? []
    : currentSupportedType.required_ext.filter(...);           // <-- no guard
// ...
missingExtensions.length === currentSupportedType.required_ext.length  // <-- no guard

But required_ext is optional in the data model — getSupportedTypeExt already guards it:

export const getSupportedTypeExt = (supportedType = {}) => {
    return [...(supportedType.required_ext || []), ...(supportedType.optional_ext || [])];
};

A supportedType declaring only optional_ext (no required_ext) still matches an upload via getSupportedTypeExt, then validateFileResourceUploads throws TypeError: Cannot read properties of undefined (reading 'includes').

(Originally raised by gemini-code-assist on #2560; that PR only reindented these lines, so the fix belongs in its own change.)

Fix

Guard the three required_ext reads with || [], matching getSupportedTypeExt. No behavior change for types that declare required_ext.

Test

Added a regression test in UploadUtils-test.js for a supported type with only optional_ext. It throws on master and passes with the fix:

✗ validateFileResourceUploads does not throw for a supported type without required_ext
  TypeError: Cannot read properties of undefined (reading 'includes')   # before
✔ validateFileResourceUploads does not throw for a supported type without required_ext  # after

Full suite: 340 tests pass (was 339), Node 20.

Note

Touches the same validateFileResourceUploads lines as #2560 (a CI lint-gate PR that reindented this file). The two are independent; whichever merges second needs a trivial whitespace rebase.

validateFileResourceUploads dereferenced currentSupportedType.required_ext
directly, but the field is optional in the data model — getSupportedTypeExt
already guards it with || []. A supported type declaring only optional_ext
matched the upload and then threw 'TypeError: Cannot read properties of
undefined (reading includes)'. Guard the three required_ext reads with || []
to match getSupportedTypeExt.

Adds a regression test (optional_ext-only type) that fails on the previous
code with the TypeError and passes after the guard. Full suite: 340 tests.
Copilot AI review requested due to automatic review settings June 9, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a potential TypeError in validateFileResourceUploads by safely guarding currentSupportedType.required_ext with a fallback empty array when it is undefined, and adds a corresponding regression test. The reviewer suggested refactoring the code to extract the repeated fallback expressions for required and optional extensions into local variables to improve readability and reduce redundancy.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread geonode_mapstore_client/client/js/utils/UploadUtils.js Outdated
…esourceUploads

Per review: replace the repeated '|| []' fallbacks with two locals
(requiredExtensions, optionalExtensions) for readability. No behavior
change; full suite still 340 tests.
@Valyrian-Code

Copy link
Copy Markdown
Author

Applied in dc8bd3b — extracted requiredExtensions and optionalExtensions locals so the fallback is computed once. No behavior change; full suite still passes (340 tests). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants