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

Unified Diff: sdk/lib/_internal/pub/lib/src/source/hosted.dart

Issue 311253005: Bind to all available loopback addresses in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 6 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
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/oauth2.dart ('k') | sdk/lib/_internal/pub/lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/source/hosted.dart
diff --git a/sdk/lib/_internal/pub/lib/src/source/hosted.dart b/sdk/lib/_internal/pub/lib/src/source/hosted.dart
index affc9b09477c7b5da39fff12cf5d311ec487e684..d9d1515a7d2640b9a30de38266dbdf9d12e91fb0 100644
--- a/sdk/lib/_internal/pub/lib/src/source/hosted.dart
+++ b/sdk/lib/_internal/pub/lib/src/source/hosted.dart
@@ -274,7 +274,9 @@ class OfflineHostedSource extends HostedSource {
///
/// This behavior is a bug, but is being preserved for compatibility.
String _urlToDirectory(String url) {
- url = url.replaceAll(new RegExp(r"^https?://"), "");
+ // Normalize all loopback URLs to "localhost".
+ url = url.replaceAllMapped(new RegExp(r"^https?://(127\.0\.0\.1|\[::1\])?"),
+ (match) => match[1] == null ? '' : 'localhost');
return replace(url, new RegExp(r'[<>:"\\/|?*%]'),
(match) => '%${match[0].codeUnitAt(0)}');
}
@@ -298,17 +300,7 @@ String _directoryToUrl(String url) {
var scheme = "https";
// See if it's a loopback IP address.
- try {
- var urlWithoutPort = url.replaceAll(new RegExp(":.*"), "");
- var address = new io.InternetAddress(urlWithoutPort);
- if (address.isLoopback) scheme = "http";
- } on ArgumentError catch(error) {
- // If we got here, it's not a raw IP address, so it's probably a regular
- // URL.
- }
-
- if (url == "localhost") scheme = "http";
-
+ if (isLoopback(url.replaceAll(new RegExp(":.*"), ""))) scheme = "http";
return "$scheme://$url";
}
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/oauth2.dart ('k') | sdk/lib/_internal/pub/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698