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/analyzer/lib/src/util/absolute_path.dart

Issue 1512363002: Paths where '..' is not right between separators are normalized. (Closed) Base URL: git@github.com:dart-lang/sdk.git@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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/util/absolute_path_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/util/absolute_path.dart
diff --git a/pkg/analyzer/lib/src/util/absolute_path.dart b/pkg/analyzer/lib/src/util/absolute_path.dart
index 2d599871a35bcfaf4e344bff871b6d34f452496f..28f5732cb94994f57155674b1e8e4eb1e0546ef0 100644
--- a/pkg/analyzer/lib/src/util/absolute_path.dart
+++ b/pkg/analyzer/lib/src/util/absolute_path.dart
@@ -7,7 +7,6 @@ library analyzer.src.util.absolute_path;
/// The class for manipulating absolute, normalized paths.
class AbsolutePathContext {
static const int _COLON = 0x3A;
- static const int _PERIOD = 0x2e;
static const int _LOWER_A = 0x61;
static const int _LOWER_Z = 0x7A;
static const int _UPPER_A = 0x41;
@@ -16,10 +15,18 @@ class AbsolutePathContext {
final bool _isWindows;
String separator;
int _separatorChar;
+ String _singlePeriodComponent;
+ String _doublePeriodComponent;
+ String _singlePeriodEnding;
+ String _doublePeriodEnding;
AbsolutePathContext(this._isWindows) {
separator = _isWindows ? r'\' : '/';
_separatorChar = separator.codeUnitAt(0);
+ _singlePeriodComponent = separator + '.' + separator;
+ _doublePeriodComponent = separator + '..' + separator;
+ _singlePeriodEnding = separator + '.';
+ _doublePeriodEnding = separator + '..';
}
/// Append the given relative [suffix] to the given absolute [parent].
@@ -125,29 +132,19 @@ class AbsolutePathContext {
}
}
-
/// Return `true` if the given absolute [path] is normalized.
///
/// _isNormalized('/foo/bar'); // -> true
/// _isNormalized('/foo/..bar'); // -> true
+ /// _isNormalized('/foo/bar..'); // -> true
/// _isNormalized('/'); // -> true
/// _isNormalized('/foo/bar/../baz'); // -> false
/// _isNormalized('/foo/bar/..'); // -> false
bool _isNormalized(String path) {
- int periodCount = 0;
- for (int c in path.codeUnits) {
- if (c == _PERIOD) {
- periodCount++;
- continue;
- }
- if (c == _separatorChar) {
- if (periodCount == 1 || periodCount == 2) {
- return false;
- }
- }
- periodCount = 0;
- }
- return periodCount != 1 && periodCount != 2;
+ return !path.contains(_singlePeriodComponent) &&
+ !path.contains(_doublePeriodComponent) &&
+ !path.endsWith(_singlePeriodEnding) &&
+ !path.endsWith(_doublePeriodEnding);
}
/// Returns whether [char] is the code for an ASCII letter (uppercase or
« no previous file with comments | « no previous file | pkg/analyzer/test/src/util/absolute_path_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698