File URL "/foo" is root-relative for Windows.
IE interprets the "/foo" file URL as though it were relative to the
current drive on Windows. We now match that behavior in
p.windows.fromUri().
See #18
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3a43eea..f7dde67 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@
[WHATWG URL specification]: https://url.spec.whatwg.org/#file-slash-state
+* When a root-relative URLs like `/foo` is converted to a Windows path using
+ `fromUrl()`, it is now resolved relative to the drive letter. This matches
+ IE's behavior.
+
## 1.4.0
* Add `equals()`, `hash()` and `canonicalize()` top-level functions and
diff --git a/lib/src/style/windows.dart b/lib/src/style/windows.dart
index ed54ab9..31114db 100644
--- a/lib/src/style/windows.dart
+++ b/lib/src/style/windows.dart
@@ -78,8 +78,13 @@
var path = uri.path;
if (uri.host == '') {
// Drive-letter paths look like "file:///C:/path/to/file". The
- // replaceFirst removes the extra initial slash.
- if (path.startsWith('/')) path = path.replaceFirst("/", "");
+ // replaceFirst removes the extra initial slash. Otherwise, leave the
+ // slash to match IE's interpretation of "/foo" as a root-relative path.
+ if (path.length >= 3 &&
+ path.startsWith('/') &&
+ isDriveLetter(path, 1)) {
+ path = path.replaceFirst("/", "");
+ }
} else {
// Network paths look like "file://hostname/path/to/file".
path = '\\\\${uri.host}$path';
diff --git a/test/windows_test.dart b/test/windows_test.dart
index f4453a7..ad58774 100644
--- a/test/windows_test.dart
+++ b/test/windows_test.dart
@@ -704,6 +704,7 @@
r'\\server\share\path\to\foo#bar');
expect(context.fromUri(Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')),
r'_{_}_`_^_ _"_%_');
+ expect(context.fromUri(Uri.parse('/foo')), r'\foo');
expect(() => context.fromUri(Uri.parse('http://dartlang.org')),
throwsArgumentError);
});