Skip to content

Commit

Permalink
Fix escape in downloadUrl (#2645)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Aug 12, 2019
1 parent d6ca74c commit 8ef1968
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 2 additions & 4 deletions app/lib/frontend/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1071,17 +1071,15 @@ class TarballStorageNamer {
(namespace == null || namespace.isEmpty) ? '' : 'ns/$namespace/';

/// The GCS object name of a tarball object - excluding leading '/'.
String tarballObjectName(String package, String version)
// TODO: Do we need some kind of escaping here?
=>
String tarballObjectName(String package, String version) =>
'${prefix}packages/$package-$version.tar.gz';

/// The GCS object name of an temporary object [guid] - excluding leading '/'.
String tmpObjectName(String guid) => 'tmp/$guid';

/// The http URL of a publicly accessable GCS object.
String tarballObjectUrl(String package, String version) {
final object = tarballObjectName(package, version);
final object = tarballObjectName(package, Uri.encodeComponent(version));
return '$storageBaseUrl/$bucket/$object';
}
}
16 changes: 12 additions & 4 deletions app/test/frontend/backend_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,18 @@ void main() {
});
});

testWithServices('Backend.downloadUrl', () async {
final url = await backend.downloadUrl('hydrogen', '2.0.8');
expect(url.toString(),
'http://localhost:0/fake-bucket-pub/packages/hydrogen-2.0.8.tar.gz');
group('Backend.downloadUrl', () {
testWithServices('no escape needed', () async {
final url = await backend.downloadUrl('hydrogen', '2.0.8');
expect(url.toString(),
'http://localhost:0/fake-bucket-pub/packages/hydrogen-2.0.8.tar.gz');
});

testWithServices('version escape needed', () async {
final url = await backend.downloadUrl('hydrogen', '2.0.8+5');
expect(url.toString(),
'http://localhost:0/fake-bucket-pub/packages/hydrogen-2.0.8%2B5.tar.gz');
});
});
});

Expand Down

0 comments on commit 8ef1968

Please sign in to comment.