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

Unified Diff: sdk/lib/core/uri.dart

Issue 438233003: Ensure that a file: URI does not have an empty path. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | « no previous file | tests/corelib/uri_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/uri.dart
diff --git a/sdk/lib/core/uri.dart b/sdk/lib/core/uri.dart
index 1e26d01f5a2116c379424f649dae60dbf819b1d5..ce9c8bb89be3617310461cd6d1af6181acfdc334 100644
--- a/sdk/lib/core/uri.dart
+++ b/sdk/lib/core/uri.dart
@@ -371,8 +371,9 @@ class Uri {
}
assert(state == NOT_IN_PATH);
- bool ensureLeadingSlash = (host != null || scheme == "file");
- path = _makePath(uri, pathStart, index, null, ensureLeadingSlash);
+ bool isFile = (scheme == "file");
+ bool ensureLeadingSlash = host != null;
+ path = _makePath(uri, pathStart, index, null, ensureLeadingSlash, isFile);
if (char == _QUESTION) {
int numberSignIndex = uri.indexOf('#', index + 1);
@@ -494,10 +495,9 @@ class Uri {
(userInfo.isNotEmpty || port != null || isFile)) {
host = "";
}
- bool ensureLeadingSlash = (host != null || isFile);
+ bool ensureLeadingSlash = host != null;
path = _makePath(path, 0, _stringOrNullLength(path), pathSegments,
- ensureLeadingSlash);
-
+ ensureLeadingSlash, isFile);
return new Uri._internal(scheme, userInfo, host, port,
path, query, fragment);
}
@@ -1018,8 +1018,9 @@ class Uri {
static String _makePath(String path, int start, int end,
Iterable<String> pathSegments,
- bool ensureLeadingSlash) {
- if (path == null && pathSegments == null) return "";
+ bool ensureLeadingSlash,
+ bool isFile) {
+ if (path == null && pathSegments == null) return isFile ? "/" : "";
if (path != null && pathSegments != null) {
throw new ArgumentError('Both path and pathSegments specified');
}
@@ -1029,7 +1030,10 @@ class Uri {
} else {
result = pathSegments.map((s) => _uriEncode(_pathCharTable, s)).join("/");
}
- if (ensureLeadingSlash && result.isNotEmpty && !result.startsWith("/")) {
+ if (result.isEmpty) {
+ if (isFile) return "/";
+ } else if ((isFile || ensureLeadingSlash) &&
+ result.codeUnitAt(0) != _SLASH) {
return "/$result";
}
return result;
« no previous file with comments | « no previous file | tests/corelib/uri_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698