Be more careful about converting between file URIs and paths.

This happened to work on Windows because it interprets forward slashes as
directory separators.

Review URL: https://codereview.chromium.org//13191011

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/stack_trace@20708 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/pkgs/stack_trace/lib/src/frame.dart b/pkgs/stack_trace/lib/src/frame.dart
index fdf4fe0..5f0777c 100644
--- a/pkgs/stack_trace/lib/src/frame.dart
+++ b/pkgs/stack_trace/lib/src/frame.dart
@@ -9,6 +9,7 @@
 import 'package:pathos/path.dart' as path;
 
 import 'trace.dart';
+import 'utils.dart';
 
 final _nativeFrameRegExp = new RegExp(
     r'^#\d+\s+([^\s].*) \((.+):(\d+):(\d+)\)$');
@@ -42,7 +43,7 @@
   String get library {
     // TODO(nweiz): handle relative URIs here as well once pathos supports that.
     if (uri.scheme != 'file') return uri.toString();
-    return path.relative(uri.path);
+    return path.relative(fileUriToPath(uri));
   }
 
   /// A human-friendly description of the code location.
diff --git a/pkgs/stack_trace/test/frame_test.dart b/pkgs/stack_trace/test/frame_test.dart
index 5c5a32e..c65f395 100644
--- a/pkgs/stack_trace/test/frame_test.dart
+++ b/pkgs/stack_trace/test/frame_test.dart
@@ -8,6 +8,7 @@
 import 'dart:uri';
 
 import 'package:pathos/path.dart' as path;
+import 'package:stack_trace/src/utils.dart';
 import 'package:stack_trace/stack_trace.dart';
 import 'package:unittest/unittest.dart';
 
@@ -42,7 +43,7 @@
     // TODO(nweiz): use URL-style paths when such a thing exists.
     var builder = new path.Builder(style: path.Style.posix);
     expect(builder.basename(frame.uri.path), equals('frame_test.dart'));
-    expect(frame.line, equals(16));
+    expect(frame.line, equals(17));
     expect(frame.column, equals(5));
     expect(frame.member, equals('getStackFrame'));
   });
@@ -113,7 +114,7 @@
     });
 
     test('returns the relative path for file URIs', () {
-      var uri = _pathToFileUri(path.join('foo', 'bar.dart'));
+      var uri = pathToFileUri(path.join('foo', 'bar.dart'));
       expect(new Frame.parse('#0 Foo ($uri:0:0)').library,
           equals(path.join('foo', 'bar.dart')));
     });
@@ -125,7 +126,7 @@
       expect(new Frame.parse('#0 Foo '
               '(http://dartlang.org/thing.dart:5:10)').location,
           equals('http://dartlang.org/thing.dart 5:10'));
-      var uri = _pathToFileUri(path.join('foo', 'bar.dart'));
+      var uri = pathToFileUri(path.join('foo', 'bar.dart'));
       expect(new Frame.parse('#0 Foo ($uri:1:2)').location,
           equals('${path.join('foo', 'bar.dart')} 1:2'));
     });
@@ -158,9 +159,3 @@
     });
   });
 }
-
-String _pathToFileUri(String pathString) {
-  pathString = path.absolute(pathString);
-  if (Platform.operatingSystem != 'windows') return 'file://$pathString';
-  return 'file:///${pathString.replaceAll("\\", "/")}';
-}
diff --git a/pkgs/stack_trace/test/trace_test.dart b/pkgs/stack_trace/test/trace_test.dart
index 2cbe48d..ed8fa6b 100644
--- a/pkgs/stack_trace/test/trace_test.dart
+++ b/pkgs/stack_trace/test/trace_test.dart
@@ -8,6 +8,7 @@
 import 'dart:uri';
 
 import 'package:pathos/path.dart' as path;
+import 'package:stack_trace/src/utils.dart';
 import 'package:stack_trace/stack_trace.dart';
 import 'package:unittest/unittest.dart';
 
@@ -91,7 +92,7 @@
   });
 
   test('.toString() nicely formats the stack trace', () {
-    var uri = _pathToFileUri(path.join('foo', 'bar.dart'));
+    var uri = pathToFileUri(path.join('foo', 'bar.dart'));
     var trace = new Trace.parse('''
 #0      Foo._bar ($uri:42:21)
 #1      zip.<anonymous closure>.zap (dart:async:0:2)
@@ -133,9 +134,3 @@
 '''));
   });
 }
-
-String _pathToFileUri(String pathString) {
-  pathString = path.absolute(pathString);
-  if (Platform.operatingSystem != 'windows') return 'file://$pathString';
-  return 'file:///${pathString.replaceAll("\\", "/")}';
-}