| Index: pkg/path/lib/src/style/url.dart
|
| diff --git a/pkg/path/lib/src/style/url.dart b/pkg/path/lib/src/style/url.dart
|
| index f383923d271100d44b6e65fd299a45df3a85c539..d5d0fdb83d206031ec9d5dc0a865a0518f620e76 100644
|
| --- a/pkg/path/lib/src/style/url.dart
|
| +++ b/pkg/path/lib/src/style/url.dart
|
| @@ -36,53 +36,30 @@ class UrlStyle extends InternalStyle {
|
|
|
| // A URI that's just "scheme://" needs an extra separator, despite ending
|
| // with "/".
|
| - var root = _getRoot(path);
|
| - return root != null && root.endsWith('://');
|
| + return path.endsWith("://") && rootLength(path) == path.length;
|
| }
|
|
|
| - String getRoot(String path) {
|
| - var root = _getRoot(path);
|
| - return root == null ? getRelativeRoot(path) : root;
|
| + int rootLength(String path) {
|
| + if (path.isEmpty) return 0;
|
| + if (isSeparator(path.codeUnitAt(0))) return 1;
|
| + 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;
|
| }
|
|
|
| - String getRelativeRoot(String path) {
|
| - if (path.isEmpty) return null;
|
| - return isSeparator(path.codeUnitAt(0)) ? "/" : null;
|
| - }
|
| + bool isRootRelative(String path) =>
|
| + path.isNotEmpty && isSeparator(path.codeUnitAt(0));
|
| +
|
| + String getRelativeRoot(String path) => isRootRelative(path) ? '/' : null;
|
|
|
| String pathFromUri(Uri uri) => uri.toString();
|
|
|
| Uri relativePathToUri(String path) => Uri.parse(path);
|
| Uri absolutePathToUri(String path) => Uri.parse(path);
|
| -
|
| - // A helper method for [getRoot] that doesn't handle relative roots.
|
| - String _getRoot(String path) {
|
| - if (path.isEmpty) return null;
|
| -
|
| - // We aren't using a RegExp for this because they're slow (issue 19090). If
|
| - // we could, we'd match against r"[a-zA-Z][-+.a-zA-Z\d]*://[^/]*".
|
| -
|
| - if (!isAlphabetic(path.codeUnitAt(0))) return null;
|
| - var start = 1;
|
| - for (; start < path.length; start++) {
|
| - var char = path.codeUnitAt(start);
|
| - if (isAlphabetic(char)) continue;
|
| - if (isNumeric(char)) continue;
|
| - if (char == chars.MINUS || char == chars.PLUS || char == chars.PERIOD) {
|
| - continue;
|
| - }
|
| -
|
| - break;
|
| - }
|
| -
|
| - if (start + 3 > path.length) return null;
|
| - if (path.substring(start, start + 3) != '://') return null;
|
| - start += 3;
|
| -
|
| - // A URL root can end with a non-"/" prefix.
|
| - while (start < path.length && !isSeparator(path.codeUnitAt(start))) {
|
| - start++;
|
| - }
|
| - return path.substring(0, start);
|
| - }
|
| }
|
|
|