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

Unified Diff: pkg/path/lib/path.dart

Issue 59133009: Properly support UNC paths in pkg/path. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 | « no previous file | pkg/path/test/windows_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/path/lib/path.dart
diff --git a/pkg/path/lib/path.dart b/pkg/path/lib/path.dart
index e91310ac5d0c7c662326fbb6fe968b00d1759aa2..3c25851cfeb146426a31317a0fcb15644d2a218d 100644
--- a/pkg/path/lib/path.dart
+++ b/pkg/path/lib/path.dart
@@ -969,7 +969,7 @@ class _WindowsStyle extends Style {
final separator = '\\';
final separatorPattern = new RegExp(r'[/\\]');
final needsSeparatorPattern = new RegExp(r'[^/\\]$');
- final rootPattern = new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])');
+ final rootPattern = new RegExp(r'^(\\\\[^\\]+\\[^\\/]+|[a-zA-Z]:[/\\])');
String pathFromUri(Uri uri) {
if (uri.scheme != '' && uri.scheme != 'file') {
@@ -990,23 +990,22 @@ class _WindowsStyle extends Style {
Uri absolutePathToUri(String path) {
var parsed = builder._parse(path);
- if (parsed.root == r'\\') {
- // Network paths become "file://hostname/path/to/file".
+ if (parsed.root.startsWith(r'\\')) {
+ // Network paths become "file://server/share/path/to/file".
- var host = parsed.parts.removeAt(0);
+ // The root is of the form "\\server\share". We want "server" to be the
+ // URI host, and "share" to be the first element of the path.
+ var rootParts = parsed.root.split('\\').where((part) => part != '');
+ parsed.parts.insert(0, rootParts.last);
- if (parsed.parts.isEmpty) {
- // If the path is a bare root (e.g. "\\hostname"), [parsed.parts] will
- // currently be empty. We add two empty components so the URL
- // constructor produces "file://hostname/", with a trailing slash.
- parsed.parts.addAll(["", ""]);
- } else if (parsed.hasTrailingSeparator) {
+ if (parsed.hasTrailingSeparator) {
// If the path has a trailing slash, add a single empty component so the
// URI has a trailing slash as well.
parsed.parts.add("");
}
- return new Uri(scheme: 'file', host: host, pathSegments: parsed.parts);
+ return new Uri(scheme: 'file', host: rootParts.first,
+ pathSegments: parsed.parts);
} else {
// Drive-letter paths become "file:///C:/path/to/file".
« no previous file with comments | « no previous file | pkg/path/test/windows_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698