Skip to content

Commit 6fc9ed1

Browse files
committed
Remove dependency on ext-intl
Fixes #6
1 parent 0d19c10 commit 6fc9ed1

12 files changed

Lines changed: 190 additions & 284 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66

77
- Added test coverage on Windows 32-bit.
8+
- Dependency on `rowbot/idna` to support international domain names without `ext-intl`.
89

910
### Changed
1011

@@ -18,6 +19,10 @@
1819
- Incorrect output encoding used when encoding was overriden to be "replacement", "utf-16", "utf-16le", or "utf-16be".
1920
- `ext-json` is now correctly listed as a dependency.
2021

22+
### Removed
23+
24+
- Dependency on `ext-intl` and `lib-ICU`.
25+
2126
## [3.0.1] - 2020-02-29
2227

2328
### Added

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
"authors": [
77
{
88
"name": "Trevor Rowbotham",
9-
"homepage": "http://trowbotham.com",
9+
"homepage": "https://trowbotham.com",
1010
"role": "Developer"
1111
}
1212
],
1313
"require": {
1414
"php": ">=7.1",
15-
"ext-intl": "*",
1615
"ext-json": "*",
1716
"ext-mbstring": "*",
18-
"lib-ICU": ">=4.6",
19-
"brick/math": "^0.8.13"
17+
"brick/math": "^0.8.13",
18+
"rowbot/idna": "^0.1.2"
2019
},
2120
"require-dev": {
2221
"guzzlehttp/guzzle": "^6.3",

phpstan.neon

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ parameters:
1414
path: src/URLSearchParams.php
1515

1616
-
17-
message: '#Strict comparison using !== between 0 and 0 will always evaluate to false\.#'
17+
message: '#Strict comparison using === between string and false will always evaluate to false\.#'
1818
path: src/String/AbstractUSVString.php
1919

2020
-
@@ -29,7 +29,3 @@ parameters:
2929
-
3030
message: '#Variable property access on Rowbot\\URL\\URLRecord\.#'
3131
path: src/State/AuthorityState.php
32-
33-
-
34-
message: '#Property Rowbot\\URL\\String\\Utf8StringIterator::\$codePoints \(array<int, string>\) does not accept array<string, mixed>\.#'
35-
path: src/String/Utf8StringIterator.php

src/Component/Host/HostParser.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rowbot\URL\Component\Host;
66

7+
use Rowbot\Idna\Idna;
78
use Rowbot\URL\Component\Host\Exception\IDNATransformException;
89
use Rowbot\URL\Component\Host\Exception\InvalidHostException;
910
use Rowbot\URL\Component\Host\Exception\InvalidIPv4AddressException;
@@ -28,27 +29,32 @@ class HostParser
2829
private const FORBIDDEN_OPAQUE_HOST_CODEPOINTS = '\x00\x09\x0A\x0D\x20#\/:<>?@[\\\\\]^';
2930
private const FORBIDDEN_HOST_CODEPOINTS = self::FORBIDDEN_OPAQUE_HOST_CODEPOINTS . '%';
3031

32+
/**
33+
* @see https://url.spec.whatwg.org/#concept-domain-to-ascii
34+
*/
3135
private function domainToAscii(string $domain, bool $beStrict = false): StringHost
3236
{
33-
$flags = IDNA::CHECK_BIDI | IDNA::CHECK_JOINERS | IDNA::NONTRANSITIONAL_PROCESSING;
34-
35-
if ($beStrict) {
36-
$flags |= IDNA::USE_STD3_ASCII_RULES | IDNA::VERIFY_DNS_LENGTH;
37+
$result = Idna::toAscii($domain, [
38+
'CheckHyphens' => false,
39+
'CheckBidi' => true,
40+
'CheckJoiners' => true,
41+
'UseSTD3ASCIIRules' => $beStrict,
42+
'Transitional_Processing' => false,
43+
'VerifyDnsLength' => $beStrict,
44+
]);
45+
$convertedDomain = $result->getDomain();
46+
47+
if ($convertedDomain === '') {
48+
// Validation error.
49+
throw new IDNATransformException();
3750
}
3851

39-
try {
40-
$result = IDNA::toAscii($domain, $flags);
41-
42-
if ($result === '') {
43-
// Validation error.
44-
throw new IDNATransformException();
45-
}
46-
47-
return new StringHost($result);
48-
} catch (IDNATransformException $e) {
52+
if ($result->hasErrors()) {
4953
// Validation error.
50-
throw $e;
54+
throw new IDNATransformException();
5155
}
56+
57+
return new StringHost($convertedDomain);
5258
}
5359

5460
/**

src/Component/Host/IDNA.php

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)