Skip to content

Commit c32f634

Browse files
committed
Fix detection of windows drive letters
1 parent 76066d6 commit c32f634

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Fixed
6+
7+
- Detection of windows drive letters
8+
39
## [3.1.6] - 2022-08-16
410

511
### Changed
612

713
- Forbid C0 control code points and U+007F DEL code point in non-opaque domain names per [whatwg/url#685](https://github.com/whatwg/url/pull/685)
14+
15+
## Fixed
16+
817
- Fix parsing IPv4-mapped IPv6 addresses due to wrong logical condition
918

1019
## [3.1.5] - 2022-01-10

src/Component/Path.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Rowbot\URL\String\AbstractStringBuffer;
88
use Rowbot\URL\String\CodePoint;
99

10+
use function strlen;
1011
use function strpbrk;
1112

1213
/**
@@ -19,7 +20,7 @@ class Path extends AbstractStringBuffer
1920
*/
2021
public function isNormalizedWindowsDriveLetter(): bool
2122
{
22-
return isset($this->string[1])
23+
return strlen($this->string) === 2
2324
&& strpbrk($this->string[0], CodePoint::ASCII_ALPHA_MASK) === $this->string[0]
2425
&& $this->string[1] === ':';
2526
}

tests/PathTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rowbot\URL\Tests;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Rowbot\URL\Component\Path;
9+
10+
class PathTest extends TestCase
11+
{
12+
public function isNormalizedWindowsDriveLetterProvider(): array
13+
{
14+
return [
15+
['c:', true],
16+
['c:/', false],
17+
['c:a', false],
18+
['4:', false],
19+
['az:', false],
20+
['a|', false],
21+
['a:|', false],
22+
['', false],
23+
['c:\\', false],
24+
['c:?', false],
25+
['c:#', false],
26+
['c:/f', false],
27+
];
28+
}
29+
30+
/**
31+
* @dataProvider isNormalizedWindowsDriveLetterProvider
32+
*/
33+
public function testIsNormalizedWindowsDriveLetter(string $input, bool $expected): void
34+
{
35+
$s = new Path($input);
36+
self::assertSame($expected, $s->isNormalizedWindowsDriveLetter());
37+
}
38+
}

0 commit comments

Comments
 (0)