Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Unified Diff: utils/pub/utils.dart

Issue 12667016: Use default-port-aware URI comparisons in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« utils/pub/command_lish.dart ('K') | « utils/pub/http.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/utils.dart
diff --git a/utils/pub/utils.dart b/utils/pub/utils.dart
index 20aa140a6510f13e323b503ac57bfba4921232c5..a48907926ff00b101c470d9bab19a0dc2c780316 100644
--- a/utils/pub/utils.dart
+++ b/utils/pub/utils.dart
@@ -310,6 +310,22 @@ String mapToQuery(Map<String, String> map) {
}).join("&");
}
+// TODO(nweiz): remove this when issue 9068 has been fixed.
+/// Whether [uri1] and [uri2] are equal. This consider HTTP URIs to default to
+/// port 80, and HTTPs URIs to default to port 443.
+bool urisEqual(Uri uri1, Uri uri2) =>
+ canonicalizeUri(uri1) == canonicalizeUri(uri2);
+
+/// Return [uri] with redundant port information removed.
+Uri canonicalizeUri(Uri uri) {
+ var sansPort = new Uri.fromComponents(
+ scheme: uri.scheme, userInfo: uri.userInfo, domain: uri.domain,
+ path: uri.path, query: uri.query, fragment: uri.fragment);
+ if (uri.scheme == 'http' && uri.port == 80) return sansPort;
+ if (uri.scheme == 'https' && uri.port == 443) return sansPort;
+ return uri;
+}
+
/// Add all key/value pairs from [source] to [destination], overwriting any
/// pre-existing values.
void mapAddAll(Map destination, Map source) =>
« utils/pub/command_lish.dart ('K') | « utils/pub/http.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698