File tree Expand file tree Collapse file tree 2 files changed +39
-7
lines changed
packages/firebase_storage/firebase_storage Expand file tree Collapse file tree 2 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -43,13 +43,13 @@ Map<String, String?>? partsFromHttpUrl(String url) {
43
43
return null ;
44
44
}
45
45
46
- // firebase storage url
47
- // 10.0.2.2 is for Android when using firebase emulator
48
- if ( decodedUrl.contains (_firebaseStorageHost ) ||
49
- decodedUrl.contains ('localhost' ) ||
50
- decodedUrl. contains ( '10.0.2.2' ) ) {
46
+ // 10.0.2.2 is used on Android emulators for connecting to the host machine's Firebase emulator.
47
+ final isEmulatorHost =
48
+ decodedUrl.contains ('localhost' ) || decodedUrl. contains ( '10.0.2.2' );
49
+ final isFirebaseStorageUrl = decodedUrl.contains (_firebaseStorageHost);
50
+ if (isFirebaseStorageUrl || isEmulatorHost ) {
51
51
String origin;
52
- if (decodedUrl. contains ( 'localhost' ) || decodedUrl. contains ( '10.0.2.2' ) ) {
52
+ if (isEmulatorHost ) {
53
53
Uri uri = Uri .parse (url);
54
54
origin = '^http?://${uri .host }:${uri .port }' ;
55
55
} else {
@@ -71,8 +71,8 @@ Map<String, String?>? partsFromHttpUrl(String url) {
71
71
'bucket' : match.group (1 ),
72
72
'path' : match.group (3 ),
73
73
};
74
- // google cloud storage url
75
74
} else {
75
+ // Google Cloud storage url
76
76
RegExp cloudStorageRegExp = RegExp (
77
77
'^https?://$_cloudStorageHost $_optionalPort /$_bucketDomain /$_cloudStoragePath ' ,
78
78
caseSensitive: false ,
Original file line number Diff line number Diff line change @@ -104,6 +104,38 @@ void main() {
104
104
expect (result? ['path' ], 'path/to/foo_bar.jpg' );
105
105
});
106
106
107
+ test (
108
+ 'parses HTTP URL correctly when using Android emulator localhost (10.0.2.2)' ,
109
+ () {
110
+ const androidLocalhost = '10.0.2.2' ;
111
+
112
+ final result = partsFromHttpUrl (
113
+ 'http://$androidLocalhost :9199/v0/b/myapp.appspot.com/o/path/to/foo_bar.jpg' );
114
+
115
+ expect (
116
+ result,
117
+ isNotNull,
118
+ reason:
119
+ 'partsFromHttpUrl should not return null for Android localhost URLs' ,
120
+ );
121
+ expect (result? ['bucket' ], 'myapp.appspot.com' );
122
+ expect (result? ['path' ], 'path/to/foo_bar.jpg' );
123
+ });
124
+
125
+ test ('parses HTTP URL correctly when using standard localhost (127.0.0.1)' ,
126
+ () {
127
+ final result = partsFromHttpUrl (
128
+ 'http://localhost:9199/v0/b/myapp.appspot.com/o/path/to/foo_bar.jpg' );
129
+
130
+ expect (
131
+ result,
132
+ isNotNull,
133
+ reason: 'partsFromHttpUrl should not return null for localhost URLs' ,
134
+ );
135
+ expect (result? ['bucket' ], 'myapp.appspot.com' );
136
+ expect (result? ['path' ], 'path/to/foo_bar.jpg' );
137
+ });
138
+
107
139
// TODO(helenaford): regexp can't handle no paths
108
140
// test('sets path to default if null', () {
109
141
// String url =
You can’t perform that action at this time.
0 commit comments