Chromium Code Reviews| 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..50a7aa5762440067cf36d896b09d8053a337d085 100644 |
| --- a/pkg/path/lib/src/style/url.dart |
| +++ b/pkg/path/lib/src/style/url.dart |
| @@ -36,13 +36,25 @@ 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("://"); |
|
nweiz
2014/08/04 20:11:58
This isn't sufficient; it fails on "foo/bar://".
Anders Johnsen
2014/08/05 08:57:13
I see.
|
| + } |
| + |
| + int rootLength(String path) { |
| + if (path.isEmpty) return 0; |
| + if (isSeparator(path.codeUnitAt(0))) return 1; |
| + int index = path.indexOf("://"); |
| + if (index >= 0) { |
| + index = path.indexOf('/', index + 3); |
|
Bob Nystrom
2014/08/04 17:17:32
Document this line please.
Anders Johnsen
2014/08/05 08:57:13
Done.
|
| + if (index > 0) return index; |
| + return path.length; |
| + } |
|
nweiz
2014/08/04 20:11:58
I believe this also fails on "foo/bar://".
Anders Johnsen
2014/08/05 08:57:13
Done.
|
| + return 0; |
| } |
| String getRoot(String path) { |
| - var root = _getRoot(path); |
| - return root == null ? getRelativeRoot(path) : root; |
| + int length = rootLength(path); |
| + if (length > 0) return path.substring(0, length); |
| + return getRelativeRoot(path); |
| } |
| String getRelativeRoot(String path) { |
| @@ -54,35 +66,4 @@ class UrlStyle extends InternalStyle { |
| 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); |
| - } |
| } |