| Index: dart/lib/compiler/implementation/util/uri_extras.dart
|
| diff --git a/dart/lib/compiler/implementation/util/uri_extras.dart b/dart/lib/compiler/implementation/util/uri_extras.dart
|
| index 9a57d983933c571ded1c9f59620a8adbf6a5f065..ecff80da3c1609c8ab271582ca7e03ec7ac05180 100644
|
| --- a/dart/lib/compiler/implementation/util/uri_extras.dart
|
| +++ b/dart/lib/compiler/implementation/util/uri_extras.dart
|
| @@ -7,23 +7,50 @@
|
| #import('dart:math');
|
| #import('dart:uri');
|
|
|
| -String relativize(Uri base, Uri uri) {
|
| - if (base.scheme == 'file' &&
|
| - base.scheme == uri.scheme &&
|
| +String relativize(Uri base, Uri uri, bool isWindows) {
|
| + if (!base.path.startsWith('/')) {
|
| + // Also throw an exception if [base] or base.path is null.
|
| + throw new IllegalArgumentException('Expected absolute path: ${base.path}');
|
| + }
|
| + if (!uri.path.startsWith('/')) {
|
| + // Also throw an exception if [uri] or uri.path is null.
|
| + throw new IllegalArgumentException('Expected absolute path: ${uri.path}');
|
| + }
|
| + bool equalsNCS(String a, String b) {
|
| + return a.toLowerCase() == b.toLowerCase();
|
| + }
|
| +
|
| + String normalize(String path) {
|
| + if (isWindows) {
|
| + return path.toLowerCase();
|
| + } else {
|
| + return path;
|
| + }
|
| + }
|
| +
|
| + if (equalsNCS(base.scheme, 'file') &&
|
| + equalsNCS(base.scheme, uri.scheme) &&
|
| base.userInfo == uri.userInfo &&
|
| - base.domain == uri.domain &&
|
| + equalsNCS(base.domain, uri.domain) &&
|
| base.port == uri.port &&
|
| uri.query == "" && uri.fragment == "") {
|
| - if (uri.path.startsWith(base.path)) {
|
| + if (normalize(uri.path).startsWith(normalize(base.path))) {
|
| return uri.path.substring(base.path.length);
|
| }
|
| List<String> uriParts = uri.path.split('/');
|
| List<String> baseParts = base.path.split('/');
|
| int common = 0;
|
| int length = min(uriParts.length, baseParts.length);
|
| - while (common < length && uriParts[common] == baseParts[common]) {
|
| + while (common < length &&
|
| + normalize(uriParts[common]) == normalize(baseParts[common])) {
|
| common++;
|
| }
|
| + if (common == 1 || (isWindows && common == 2)) {
|
| + // The first part will always be an empty string because the
|
| + // paths are absolute. On Windows, we must also consider drive
|
| + // letters or hostnames.
|
| + return uri.path;
|
| + }
|
| StringBuffer sb = new StringBuffer();
|
| for (int i = common + 1; i < baseParts.length; i++) {
|
| sb.add('../');
|
|
|