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

Side by Side Diff: lib/src/context.dart

Issue 1491503002: Make sure we normalize relative()'s return value. (Closed) Base URL: git@github.com:dart-lang/path@master
Patch Set: Created 5 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library path.context; 5 library path.context;
6 6
7 import 'characters.dart' as chars; 7 import 'characters.dart' as chars;
8 import 'internal_style.dart'; 8 import 'internal_style.dart';
9 import 'style.dart'; 9 import 'style.dart';
10 import 'parsed_path.dart'; 10 import 'parsed_path.dart';
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 /// 405 ///
406 /// var context = new Context(r'some/relative/path'); 406 /// var context = new Context(r'some/relative/path');
407 /// context.relative(r'/absolute/path'); // -> '/absolute/path' 407 /// context.relative(r'/absolute/path'); // -> '/absolute/path'
408 /// 408 ///
409 /// If [root] is relative, it may be impossible to determine a path from 409 /// If [root] is relative, it may be impossible to determine a path from
410 /// [from] to [path]. For example, if [root] and [path] are "." and [from] is 410 /// [from] to [path]. For example, if [root] and [path] are "." and [from] is
411 /// "/", no path can be determined. In this case, a [PathException] will be 411 /// "/", no path can be determined. In this case, a [PathException] will be
412 /// thrown. 412 /// thrown.
413 String relative(String path, {String from}) { 413 String relative(String path, {String from}) {
414 // Avoid expensive computation if the path is already relative. 414 // Avoid expensive computation if the path is already relative.
415 if (from == null && this.isRelative(path)) return path; 415 if (from == null && this.isRelative(path)) return this.normalize(path);
416 416
417 // Avoid calling [current] since it is slow and calling join() when 417 // Avoid calling [current] since it is slow and calling join() when
418 // [from] is absolute does nothing. 418 // [from] is absolute does nothing.
419 if (from == null) { 419 if (from == null) {
420 from = current; 420 from = current;
421 } else if (this.isRelative(from) || this.isRootRelative(from)) { 421 } else if (this.isRelative(from) || this.isRootRelative(from)) {
422 from = this.join(current, from); 422 from = this.join(current, from);
423 } 423 }
424 424
425 // We can't determine the path from a relative path to an absolute path. 425 // We can't determine the path from a relative path to an absolute path.
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 var message = new StringBuffer(); 646 var message = new StringBuffer();
647 message.write("$method("); 647 message.write("$method(");
648 message.write(args 648 message.write(args
649 .take(numArgs) 649 .take(numArgs)
650 .map((arg) => arg == null ? "null" : '"$arg"') 650 .map((arg) => arg == null ? "null" : '"$arg"')
651 .join(", ")); 651 .join(", "));
652 message.write("): part ${i - 1} was null, but part $i was not."); 652 message.write("): part ${i - 1} was null, but part $i was not.");
653 throw new ArgumentError(message.toString()); 653 throw new ArgumentError(message.toString());
654 } 654 }
655 } 655 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698