Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Improve docs, add changelog, additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Aug 9, 2023
1 parent 02ad12e commit 906082b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 1.8.4-wip
## 1.9.0-wip

* Require Dart 3.0
* Fixed an issue with the `split` method doc comment.
* Allow percent-encoded colons (`%3a`) in drive letters in `fromUri`.

## 1.8.3

Expand Down
13 changes: 11 additions & 2 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ bool isNumeric(int char) => char >= chars.zero && char <= chars.nine;
bool isDriveLetter(String path, int index) =>
driveLetterEnd(path, index) != null;

/// Returns the index of the first character after the drive letter, or `null`
/// if [index] is not the start of a drive letter.
/// Returns the index of the first character after the drive letter or a
/// URL-formatted path, or `null` if [index] is not the start of a drive letter.
/// A valid drive letter must be followed by a colon and then either a `/` or
/// the end of string.
///
/// ```
/// d:/abc => 3
/// d:/ => 3
/// d: => 2
/// d => null
/// ```
int? driveLetterEnd(String path, int index) {
if (path.length < index + 2) return null;
if (!isAlphabetic(path.codeUnitAt(index))) return null;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: path
version: 1.8.4-wip
version: 1.9.0-wip
description: >-
A string-based path manipulation library. All of the path operations you know
and love, with solid support for Windows, POSIX (Linux and Mac OS X), and the
Expand Down
28 changes: 27 additions & 1 deletion test/windows_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:path/path.dart' as path;
import 'package:path/src/utils.dart';
import 'package:test/test.dart';

import 'utils.dart';
Expand Down Expand Up @@ -43,7 +44,7 @@ void main() {
expect(context.rootPrefix('a'), '');
expect(context.rootPrefix(r'a\b'), '');
expect(context.rootPrefix(r'C:\a\c'), r'C:\');
expect(context.rootPrefix('C:\\'), r'C:\');
expect(context.rootPrefix(r'C:\'), r'C:\');
expect(context.rootPrefix('C:/'), 'C:/');
expect(context.rootPrefix(r'\\server\share\a\b'), r'\\server\share');
expect(context.rootPrefix(r'\\server\share'), r'\\server\share');
Expand Down Expand Up @@ -877,4 +878,29 @@ void main() {
expect(context.prettyUri(Uri.parse('a/b')), r'a\b');
});
});

test('driveLetterEnd', () {
expect(driveLetterEnd('', 0), null);
expect(driveLetterEnd('foo.dart', 0), null);
expect(driveLetterEnd('@', 0), null);

expect(driveLetterEnd('c:', 0), 2);

// colons
expect(driveLetterEnd('c:/', 0), 3);
expect(driveLetterEnd('c:/a', 0), 3);

// escaped colons lowercase
expect(driveLetterEnd('c%3a/', 0), 5);
expect(driveLetterEnd('c%3a/a', 0), 5);

// escaped colons uppercase
expect(driveLetterEnd('c%3A/', 0), 5);
expect(driveLetterEnd('c%3A/a', 0), 5);

// non-drive letter
expect(driveLetterEnd('ab:/c', 0), null);
expect(driveLetterEnd('ab%3a/c', 0), null);
expect(driveLetterEnd('ab%3A/c', 0), null);
});
}

0 comments on commit 906082b

Please sign in to comment.