Skip to content

Fix Reference.fullPath to return the bucket-relative slash-path - #46

Merged
atn832 merged 1 commit into
atn832:masterfrom
nickmeinhold:fix-fullpath-slash-path
Jun 5, 2026
Merged

atn832 merged 1 commit into
atn832:masterfrom
nickmeinhold:fix-fullpath-slash-path

Conversation

@nickmeinhold

Copy link
Copy Markdown
Contributor

Problem

MockReference.fullPath returns a gs://{bucket}{path} URI:

String get fullPath {
  return 'gs://${_storage.bucket}$_path';
}

But real Firebase Storage's Reference.fullPath returns the bucket-relative slash-path — no gs://{bucket} prefix and no leading slash. For example, storage.ref().child('images/photo.png').fullPath is images/photo.png, not gs://some-bucket/images/photo.png.

Because the path is concatenated without a separator, a nested ref like storage.ref('/images').child('/photo.png') even produced gs://some-bucketimages/photo.png under the mock.

This bites downstream code that synthesises its own gs://{bucket}/{fullPath} URIs from a reference: under the mock it yields a doubled gs://some-bucket/gs://some-bucket... prefix that never occurs against real Storage, forcing tests to encode the quirk.

Fix

fullPath now strips the gs://{bucket} prefix and the leading slash, returning the bucket-relative slash-path that matches real Firebase.

  • Updated the existing fullPath expectations (gs://some-bucket/someimage.png → someimage.png).
  • Added tests pinning the slash-path contract for top-level and nested refs, and asserting there is no gs:// prefix.

All tests pass (flutter test → 19 passing).

`MockReference.fullPath` returned `gs://{bucket}{path}` (e.g.
`gs://some-bucketimages/photo.png`), but real Firebase Storage's
`Reference.fullPath` returns the bucket-relative slash-path with no
`gs://{bucket}` prefix and no leading slash (e.g. `images/photo.png`).

This bit a downstream test that synthesises `gs://{bucket}/{fullPath}`
URIs: under the mock it produced a doubled `gs://some-bucket/gs://some-bucket...`
prefix that doesn't occur against real Storage.

Fix `fullPath` to strip the `gs://{bucket}` prefix and the leading
slash, and update the existing `fullPath` expectations plus add tests
pinning the slash-path contract for top-level and nested references.
// (e.g. `images/someimage.png`), NOT a `gs://{bucket}` URI. The leading
// slash is also stripped to match real `Reference.fullPath`, where the
// root reference's `fullPath` is the empty string. See
// https://firebase.google.com/docs/reference/js/storage.reference.md#referencefullpath

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This url returns error 404. It seems to have moved to https://firebase.google.com/docs/reference/js/storage.storagereference.md#storagereferencefullpath. I can fix it after I merge your PR

@atn832
atn832 merged commit 0a557c1 into atn832:master Jun 5, 2026
2 checks passed
@atn832

atn832 commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Thank you for your fix @nickmeinhold! I just published it at https://pub.dev/packages/firebase_storage_mocks/changelog#081.

@nickmeinhold
nickmeinhold deleted the fix-fullpath-slash-path branch June 6, 2026 04:48
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