Skip to content

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

Open
singhvishalkr wants to merge 2 commits into
gatsbyjs:masterfrom
singhvishalkr:fix/source-filesystem-null-pathname
Open

fix(gatsby-source-filesystem): guard against null pathname in getParsedPath#39549
singhvishalkr wants to merge 2 commits into
gatsbyjs:masterfrom
singhvishalkr:fix/source-filesystem-null-pathname

Conversation

@singhvishalkr
Copy link
Copy Markdown

Description

Fixes #39532

getParsedPath in gatsby-source-filesystem calls path.parse(Url.parse(url).pathname) without guarding against null. For malformed or edge-case URL inputs where Url.parse(url).pathname returns null, path.parse throws a TypeError.

Fix

Added a || '' fallback so path.parse always receives a string, consistent with the TypeScript equivalent in gatsby-core-utils which already includes this guard.

Files Changed

  • packages/gatsby-source-filesystem/src/utils.js -- 1 line change

Related Issues

@gatsbot gatsbot Bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 20, 2026
…back

ESLint quotes: backtick rule in this codebase requires template literals rather than single-quoted strings, so change the '' fallback in getParsedPath() to an empty template literal to satisfy yarn lint:code.
@singhvishalkr
Copy link
Copy Markdown
Author

CI update after the lint fix (commit eb5d213):

  • lint, build-test, integration_tests_images-18.2.0 — now green.
  • Two e2e_tests_pnp jobs (18.2.0 and 24.11.1) still red, but the failure is EROFS: read-only filesystem, open ''/node_modules/gatsby/latest-adapters.js'' inside ZipFS.writeFilePromise in the Yarn PnP .pnp.cjs — i.e. the build tries to write latest-adapters.js into the read-only PnP virtual filesystem. Same stack hits docs(gatsby): fix typos in user-facing strings and docs #39550 on unrelated code, so this looks like a gatsby-side infrastructure/PnP regression rather than anything in this one-line patch (only change here is Url.parse(url).pathname || `` in gatsby-source-filesystem/src/utils.js).

Happy to help debug the PnP build if it would be useful, otherwise the PR should be ready for review on the code side.

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