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

Unified Diff: packages/path/lib/src/style/url.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 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 | « packages/path/lib/src/style/posix.dart ('k') | packages/path/lib/src/style/windows.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « packages/path/lib/src/style/posix.dart ('k') | packages/path/lib/src/style/windows.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698