Uri.https and Uri.http constructors queryParams type

Currently `Uri.http` and `Uri.https` factory constructors do not allow for `queryParameters` to be `Map<String, dynamic>`, but only `Map<String, String>`, when in fact the main `Uri` constructor does work with `queryParameters` as `Map<String, dynamic>`.

Closes https://github.com/dart-lang/sdk/pull/42564
https://github.com/dart-lang/sdk/pull/42564

GitOrigin-RevId: 6fa130cc4325ae99d96260e8dc0a222398e7522f
Change-Id: Ia1ee0911ec4d80df75792a365af9ca143a729fa2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163620
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
This commit is contained in:
Lasse R.H. Nielsen 2021-01-11 15:22:06 +00:00 committed by commit-bot@chromium.org
parent 318babd5ac
commit eaf5be7b80
4 changed files with 68 additions and 11 deletions

View file

@ -237,6 +237,11 @@ This is a patch release that fixes the following issues:
* Class `BytesBuilder` is moved from `dart:io` to `dart:typed_data`.
It's temporarily being exported from `dart:io` as well.
### `dart:uri`
* [#42564]: Solved inconsistency in `Uri.https` and `Uri.http` constructors'
`queryParams` type.
### Dart VM
* **Breaking Change** [#42982][]: `dart_api_dl.cc` is renamed to

View file

@ -163,7 +163,7 @@ abstract class Uri {
* argument.
*/
factory Uri.http(String authority, String unencodedPath,
[Map<String, String>? queryParameters]) = _Uri.http;
[Map<String, dynamic>? queryParameters]) = _Uri.http;
/**
* Creates a new `https` URI from authority, path and query.
@ -172,7 +172,7 @@ abstract class Uri {
* which is set to `https`.
*/
factory Uri.https(String authority, String unencodedPath,
[Map<String, String>? queryParameters]) = _Uri.https;
[Map<String, dynamic>? queryParameters]) = _Uri.https;
/**
* Creates a new file URI from an absolute or relative file path.
@ -1543,13 +1543,13 @@ class _Uri implements Uri {
/// Implementation of [Uri.http].
factory _Uri.http(String authority, String unencodedPath,
[Map<String, String>? queryParameters]) {
[Map<String, dynamic>? queryParameters]) {
return _makeHttpUri("http", authority, unencodedPath, queryParameters);
}
/// Implementation of [Uri.https].
factory _Uri.https(String authority, String unencodedPath,
[Map<String, String>? queryParameters]) {
[Map<String, dynamic>? queryParameters]) {
return _makeHttpUri("https", authority, unencodedPath, queryParameters);
}
@ -1630,7 +1630,7 @@ class _Uri implements Uri {
}
static _Uri _makeHttpUri(String scheme, String? authority,
String unencodedPath, Map<String, String>? queryParameters) {
String unencodedPath, Map<String, dynamic>? queryParameters) {
var userInfo = "";
String? host;
int? port;

View file

@ -4,7 +4,7 @@
import "package:expect/expect.dart";
testHttpUri() {
void testHttpUri() {
void check(Uri uri, String expected) {
Expect.equals(expected, uri.toString());
}
@ -40,7 +40,7 @@ testHttpUri() {
check(new Uri.http('[ff02::1%%321]', ''), 'http://[ff02::1%2521]');
}
testHttpsUri() {
void testHttpsUri() {
void check(Uri uri, String expected) {
Expect.equals(expected, uri.toString());
}
@ -71,7 +71,7 @@ testHttpsUri() {
check(new Uri.https("[::127.0.0.1]", "a"), "https://[::127.0.0.1]/a");
}
testResolveHttpScheme() {
void testResolveHttpScheme() {
String s = "//myserver:1234/path/some/thing";
Uri uri = Uri.parse(s);
Uri http = new Uri(scheme: "http");
@ -80,8 +80,34 @@ testResolveHttpScheme() {
Expect.equals("https:$s", https.resolveUri(uri).toString());
}
void testQuery() {
var uri = Uri.http("example.com", "a/b", <String, dynamic>{
"a": "b",
"c": ["d", "e"]
});
Expect.equals(uri.toString(), "http://example.com/a/b?a=b&c=d&c=e");
Expect.listEquals(uri.queryParametersAll["c"]!, ["d", "e"]);
uri = Uri.https("example.com", "a/b", <String, dynamic>{
"a": "b",
"c": ["d", "e"]
});
Expect.equals(uri.toString(), "https://example.com/a/b?a=b&c=d&c=e");
Expect.listEquals(uri.queryParametersAll["c"]!, ["d", "e"]);
uri = Uri.http("example.com", "a/b", {
"a b c": ["d e", "f g"]
});
Expect.equals(uri.toString(), "http://example.com/a/b?a+b+c=d+e&a+b+c=f+g");
uri = Uri.https("example.com", "a/b", {
"a b c": ["d e", "f g"]
});
Expect.equals(uri.toString(), "https://example.com/a/b?a+b+c=d+e&a+b+c=f+g");
}
main() {
testHttpUri();
testHttpsUri();
testResolveHttpScheme();
testQuery();
}

View file

@ -4,7 +4,7 @@
import "package:expect/expect.dart";
testHttpUri() {
void testHttpUri() {
void check(Uri uri, String expected) {
Expect.equals(expected, uri.toString());
}
@ -40,7 +40,7 @@ testHttpUri() {
check(new Uri.http('[ff02::1%%321]', ''), 'http://[ff02::1%2521]');
}
testHttpsUri() {
void testHttpsUri() {
void check(Uri uri, String expected) {
Expect.equals(expected, uri.toString());
}
@ -71,7 +71,7 @@ testHttpsUri() {
check(new Uri.https("[::127.0.0.1]", "a"), "https://[::127.0.0.1]/a");
}
testResolveHttpScheme() {
void testResolveHttpScheme() {
String s = "//myserver:1234/path/some/thing";
Uri uri = Uri.parse(s);
Uri http = new Uri(scheme: "http");
@ -80,8 +80,34 @@ testResolveHttpScheme() {
Expect.equals("https:$s", https.resolveUri(uri).toString());
}
void testQuery() {
var uri = Uri.http("example.com", "a/b", <String, dynamic>{
"a": "b",
"c": ["d", "e"]
});
Expect.equals(uri.toString(), "http://example.com/a/b?a=b&c=d&c=e");
Expect.listEquals(uri.queryParametersAll["c"], ["d", "e"]);
uri = Uri.https("example.com", "a/b", <String, dynamic>{
"a": "b",
"c": ["d", "e"]
});
Expect.equals(uri.toString(), "https://example.com/a/b?a=b&c=d&c=e");
Expect.listEquals(uri.queryParametersAll["c"], ["d", "e"]);
uri = Uri.http("example.com", "a/b", {
"a b c": ["d e", "f g"]
});
Expect.equals(uri.toString(), "http://example.com/a/b?a+b+c=d+e&a+b+c=f+g");
uri = Uri.https("example.com", "a/b", {
"a b c": ["d e", "f g"]
});
Expect.equals(uri.toString(), "https://example.com/a/b?a+b+c=d+e&a+b+c=f+g");
}
main() {
testHttpUri();
testHttpsUri();
testResolveHttpScheme();
testQuery();
}