Skip to content

fix(gatsby-source-filesystem): guard against null pathname in getParsedPath#39535

Open
funsaized wants to merge 2 commits intogatsbyjs:masterfrom
funsaized:fix/null-pathname-guard
Open

fix(gatsby-source-filesystem): guard against null pathname in getParsedPath#39535
funsaized wants to merge 2 commits intogatsbyjs:masterfrom
funsaized:fix/null-pathname-guard

Conversation

@funsaized
Copy link
Copy Markdown

Summary

Fixes #39532

getParsedPath in gatsby-source-filesystem/src/utils.js calls path.parse(Url.parse(url).pathname) without a null fallback. For malformed or edge-case URL inputs where Url.parse(url).pathname returns null, path.parse throws a TypeError, crashing callers like getRemoteFileExtension and getRemoteFileName.

Changes

  • Added || '' fallback to Url.parse(url).pathname in getParsedPath, matching the existing guard in the TypeScript equivalent at gatsby-core-utils/src/filename-utils.ts (line 12)
  • Added test case verifying that empty strings and mailto: URLs no longer throw

Before

function getParsedPath(url) {
  return path.parse(Url.parse(url).pathname)  // throws TypeError when pathname is null
}

After

function getParsedPath(url) {
  return path.parse(Url.parse(url).pathname || ``)  // safe fallback, matches gatsby-core-utils
}

@gatsbot gatsbot Bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(gatsby-source-filesystem): url pathname can be null, causing path.parse to throw in filesystem utils

1 participant