Skip to content

Commit

Permalink
fix(storage): update regex for cloudStoragePath (#16847)
Browse files Browse the repository at this point in the history
  • Loading branch information
SelaseKay authored Dec 11, 2024
1 parent 6354901 commit b083217
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const String _cloudStorageHost =
const String _bucketDomain = r'([A-Za-z0-9.\-_]+)';
const String _version = 'v[A-Za-z0-9_]+';
const String _firebaseStoragePath = r'(/([^?#]*).*)?$';
const String _cloudStoragePath = r'([^?#]*)*$';
// Matches the implementation in the Web SDK:
// https://github.com/firebase/firebase-js-sdk/blob/main/packages/storage/src/implementation/location.ts#L101
const String _cloudStoragePath = '([^?#]*)';
const String _optionalPort = r'(?::\d+)?';

/// Returns a path from a given `http://` or `https://` URL.
Expand Down
10 changes: 10 additions & 0 deletions packages/firebase_storage/firebase_storage/test/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ void main() {
expect(result?['path'], 'foo+bar/file with spaces .png');
});

test('parses a https url with query param', () {
String url =
'https://storage.cloud.google.com/valid-url.appspot.com/path/to/foo_bar.jpg?foo=bar';

final result = partsFromHttpUrl(url);

expect(result?['bucket'], 'valid-url.appspot.com');
expect(result?['path'], 'path/to/foo_bar.jpg');
});

// TODO(helenaford): regexp can't handle no paths
// test('sets path to default if null', () {
// String url =
Expand Down

0 comments on commit b083217

Please sign in to comment.