| Index: packages/path/lib/src/style/url.dart
|
| diff --git a/packages/path/lib/src/style/url.dart b/packages/path/lib/src/style/url.dart
|
| index 255f22a6ff7ff933910d0a138eea3729335a1950..2e29aa701e4ae73793e547fea2f99700eca511e1 100644
|
| --- a/packages/path/lib/src/style/url.dart
|
| +++ b/packages/path/lib/src/style/url.dart
|
| @@ -2,10 +2,9 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -library path.style.url;
|
| -
|
| import '../characters.dart' as chars;
|
| import '../internal_style.dart';
|
| +import '../utils.dart';
|
|
|
| /// The style for URL paths.
|
| class UrlStyle extends InternalStyle {
|
| @@ -38,16 +37,33 @@ class UrlStyle extends InternalStyle {
|
| return path.endsWith("://") && rootLength(path) == path.length;
|
| }
|
|
|
| - int rootLength(String path) {
|
| + int rootLength(String path, {bool withDrive: false}) {
|
| if (path.isEmpty) return 0;
|
| if (isSeparator(path.codeUnitAt(0))) return 1;
|
| +
|
| + for (var i = 0; i < path.length; i++) {
|
| + var codeUnit = path.codeUnitAt(i);
|
| + if (isSeparator(codeUnit)) return 0;
|
| + if (codeUnit == chars.COLON) {
|
| + if (i == 0) return 0;
|
| +
|
| + // The root part is up until the next '/', or the full path. Skip ':'
|
| + // (and '//' if it exists) and search for '/' after that.
|
| + if (path.startsWith('//', i + 1)) i += 3;
|
| + var index = path.indexOf('/', i);
|
| + if (index <= 0) return path.length;
|
| +
|
| + // file: URLs sometimes consider Windows drive letters part of the root.
|
| + // See https://url.spec.whatwg.org/#file-slash-state.
|
| + if (!withDrive || path.length < index + 3) return index;
|
| + if (!path.startsWith('file://')) return index;
|
| + if (!isDriveLetter(path, index + 1)) return index;
|
| + return path.length == index + 3 ? index + 3 : index + 4;
|
| + }
|
| + }
|
| +
|
| var index = path.indexOf("/");
|
| if (index > 0 && path.startsWith('://', index - 1)) {
|
| - // The root part is up until the next '/', or the full path. Skip
|
| - // '://' and search for '/' after that.
|
| - index = path.indexOf('/', index + 2);
|
| - if (index > 0) return index;
|
| - return path.length;
|
| }
|
| return 0;
|
| }
|
|
|