Chromium Code Reviews| Index: pkg/barback/lib/src/asset_id.dart |
| diff --git a/pkg/barback/lib/src/asset_id.dart b/pkg/barback/lib/src/asset_id.dart |
| index c4ed1d86cd1986e4d435ca4cc1faafa7e6506c8c..f5e9f82bec3e499e39abff3fea862d413d456d30 100644 |
| --- a/pkg/barback/lib/src/asset_id.dart |
| +++ b/pkg/barback/lib/src/asset_id.dart |
| @@ -6,9 +6,6 @@ library barback.asset_id; |
| import 'package:path/path.dart' as pathos; |
| -/// AssetIDs always use POSIX style paths regardless of the host platform. |
| -final _posix = new pathos.Builder(style: pathos.Style.posix); |
| - |
| /// Identifies an asset within a package. |
| class AssetId implements Comparable<AssetId> { |
| /// The name of the package containing this asset. |
| @@ -29,10 +26,18 @@ class AssetId implements Comparable<AssetId> { |
| String get extension => pathos.extension(path); |
| /// Creates a new AssetId at [path] within [package]. |
| + /// |
| + /// The [path] will be normalized: any backslashes will be replaced with |
| + /// forward slashes (regardless of host OS) and "." and ".." will be removed |
| + /// where possible. |
| AssetId(this.package, String path) |
| - : path = _posix.normalize(path); |
| + : path = _normalizePath(path); |
| /// Parses an [AssetId] string of the form "package|path/to/asset.txt". |
| + /// |
| + /// The [path] will be normalized: any backslashes will be replaced with |
| + /// forward slashes (regardless of host OS) and "." and ".." will be removed |
| + /// where possible. |
| factory AssetId.parse(String description) { |
| var parts = description.split("|"); |
| if (parts.length != 2) { |
| @@ -92,3 +97,11 @@ class AssetId implements Comparable<AssetId> { |
| /// and passed to [deserialize]. |
| serialize() => [package, path]; |
| } |
| + |
| +String _normalizePath(String path) { |
|
nweiz
2013/08/22 20:57:14
It might be nice to assert that [path] is relative
Bob Nystrom
2013/08/22 21:37:19
Done.
|
| + // Normalize path separators so that they are always "/" in the AssetID. |
| + path = path.replaceAll(r"\", "/"); |
| + |
| + // Collapse "." and "..". |
| + return pathos.posix.normalize(path); |
| +} |