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

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

Issue 2117453002: Fix regression for the one case where we deliberately don't follow the RFC. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixed Created 4 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 | « 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 211c78e1a5138d3f07f26cae3fdcd799e4c62b5f..a01b6701df1498407e28a369bec6650d1e13f320 100644
--- a/sdk/lib/core/uri.dart
+++ b/sdk/lib/core/uri.dart
@@ -902,50 +902,73 @@ abstract class Uri {
end = uri.length;
} else if (pathStart == queryStart) {
// Uri has authority and empty path. Add "/" as path.
- uri = "${uri.substring(start, pathStart)}/"
- "${uri.substring(queryStart, end)}";
- schemeEnd -= start;
- hostStart -= start;
- portStart -= start;
- pathStart -= start;
- queryStart += 1 - start;
- fragmentStart += 1 - start;
- start = 0;
- end = uri.length;
+ if (start == 0 && end == uri.length) {
+ uri = uri.replaceRange(pathStart, queryStart, "/");
+ queryStart += 1;
+ fragmentStart += 1;
+ end += 1;
+ } else {
+ uri = "${uri.substring(start, pathStart)}/"
+ "${uri.substring(queryStart, end)}";
+ schemeEnd -= start;
+ hostStart -= start;
+ portStart -= start;
+ pathStart -= start;
+ queryStart += 1 - start;
+ fragmentStart += 1 - start;
+ start = 0;
+ end = uri.length;
+ }
}
} else if (uri.startsWith("http", start)) {
scheme = "http";
// HTTP URIs should not have an explicit port of 80.
if (portStart > start && portStart + 3 == pathStart &&
uri.startsWith("80", portStart + 1)) {
+ if (start == 0 && end == uri.length) {
+ uri = uri.replaceRange(portStart, pathStart, "");
+ pathStart -= 3;
+ queryStart -= 3;
+ fragmentStart -= 3;
+ end -= 3;
+ } else {
+ uri = uri.substring(start, portStart) +
+ uri.substring(pathStart, end);
+ schemeEnd -= start;
+ hostStart -= start;
+ portStart -= start;
+ pathStart -= 3 + start;
+ queryStart -= 3 + start;
+ fragmentStart -= 3 + start;
+ start = 0;
+ end = uri.length;
+ }
+ }
+ }
+ } else if (schemeEnd == start + 5 && uri.startsWith("https", start)) {
+ scheme = "https";
+ // HTTPS URIs should not have an explicit port of 443.
+ if (portStart > start && portStart + 4 == pathStart &&
+ uri.startsWith("443", portStart + 1)) {
+ if (start == 0 && end == uri.length) {
+ uri = uri.replaceRange(portStart, pathStart, "");
+ pathStart -= 4;
+ queryStart -= 4;
+ fragmentStart -= 4;
+ end -= 3;
+ } else {
uri = uri.substring(start, portStart) +
uri.substring(pathStart, end);
schemeEnd -= start;
hostStart -= start;
portStart -= start;
- pathStart -= 3 + start;
- queryStart -= 3 + start;
- fragmentStart -= 3 + start;
+ pathStart -= 4 + start;
+ queryStart -= 4 + start;
+ fragmentStart -= 4 + start;
start = 0;
end = uri.length;
}
}
- } else if (schemeEnd == start + 5 && uri.startsWith("https", start)) {
- scheme = "https";
- // HTTPS URIs should not have an explicit port of 443.
- if (portStart > start && portStart + 4 == pathStart &&
- uri.startsWith("443", portStart + 1)) {
- uri = uri.substring(start, portStart) +
- uri.substring(pathStart, end);
- schemeEnd -= start;
- hostStart -= start;
- portStart -= start;
- pathStart -= 4 + start;
- queryStart -= 4 + start;
- fragmentStart -= 4 + start;
- start = 0;
- end = uri.length;
- }
}
}
}
@@ -4331,6 +4354,14 @@ class _SimpleUri implements Uri {
if (backCount == 0) break;
}
}
+ // If the base URI has no scheme or authority (`_pathStart == 0`)
+ // and a relative path, and we reached the beginning of the path,
+ // we have a special case.
+ if (baseEnd == 0 && !base.hasAbsolutePath) {
+ // Non-RFC 3986 behavior when resolving a purely relative path on top of
+ // another relative path: Don't make the result absolute.
+ insert = "";
+ }
var delta = baseEnd - refStart + insert.length;
var newUri = "${base._uri.substring(0, baseEnd)}$insert"
« 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