Skip to content

Commit

Permalink
Merge pull request #142 from thephpleague/bugfix/issue-141-intl-no-re…
Browse files Browse the repository at this point in the history
…quired

remove intl requirement in Uri class
  • Loading branch information
nyamsprod committed Nov 20, 2019
2 parents f8f7b68 + 233e016 commit 450e4db
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All Notable changes to `League\Uri` will be documented in this file

## Next - TBD

### Added

- Nothing

### Fixed

- `Uri` should not depend on `intl` extension if the host is in its ascii form [#141](https://github.com/thephpleague/uri/issues/141)

### Deprecated

- Nothing

### Remove

- Nothing

## 6.0.0 - 2019-10-18

### Added
Expand Down
39 changes: 20 additions & 19 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,6 @@ final class Uri implements UriInterface
*/
private const REGEXP_WINDOW_PATH = ',^(?<root>[a-zA-Z][:|\|]),';

/**
* IDNA errors.
*/
private const IDNA_ERRORS = [
IDNA_ERROR_EMPTY_LABEL => 'a non-final domain name label (or the whole domain name) is empty',
IDNA_ERROR_LABEL_TOO_LONG => 'a domain name label is longer than 63 bytes',
IDNA_ERROR_DOMAIN_NAME_TOO_LONG => 'a domain name is longer than 255 bytes in its storage form',
IDNA_ERROR_LEADING_HYPHEN => 'a label starts with a hyphen-minus ("-")',
IDNA_ERROR_TRAILING_HYPHEN => 'a label ends with a hyphen-minus ("-")',
IDNA_ERROR_HYPHEN_3_4 => 'a label contains hyphen-minus ("-") in the third and fourth positions',
IDNA_ERROR_LEADING_COMBINING_MARK => 'a label starts with a combining mark',
IDNA_ERROR_DISALLOWED => 'a label or domain name contains disallowed characters',
IDNA_ERROR_PUNYCODE => 'a label starts with "xn--" but does not contain valid Punycode',
IDNA_ERROR_LABEL_HAS_DOT => 'a label contains a dot=full stop',
IDNA_ERROR_INVALID_ACE_LABEL => 'An ACE label does not contain a valid label string',
IDNA_ERROR_BIDI => 'a label does not meet the IDNA BiDi requirements (for right-to-left characters)',
IDNA_ERROR_CONTEXTJ => 'a label does not meet the IDNA CONTEXTJ requirements',
];

/**
* Supported schemes and corresponding default port.
Expand Down Expand Up @@ -469,8 +451,27 @@ private function formatRegisteredName(string $host): string
*/
private function getIDNAErrors(int $error_byte): string
{
/**
* IDNA errors.
*/
static $idnErrors = [
IDNA_ERROR_EMPTY_LABEL => 'a non-final domain name label (or the whole domain name) is empty',
IDNA_ERROR_LABEL_TOO_LONG => 'a domain name label is longer than 63 bytes',
IDNA_ERROR_DOMAIN_NAME_TOO_LONG => 'a domain name is longer than 255 bytes in its storage form',
IDNA_ERROR_LEADING_HYPHEN => 'a label starts with a hyphen-minus ("-")',
IDNA_ERROR_TRAILING_HYPHEN => 'a label ends with a hyphen-minus ("-")',
IDNA_ERROR_HYPHEN_3_4 => 'a label contains hyphen-minus ("-") in the third and fourth positions',
IDNA_ERROR_LEADING_COMBINING_MARK => 'a label starts with a combining mark',
IDNA_ERROR_DISALLOWED => 'a label or domain name contains disallowed characters',
IDNA_ERROR_PUNYCODE => 'a label starts with "xn--" but does not contain valid Punycode',
IDNA_ERROR_LABEL_HAS_DOT => 'a label contains a dot=full stop',
IDNA_ERROR_INVALID_ACE_LABEL => 'An ACE label does not contain a valid label string',
IDNA_ERROR_BIDI => 'a label does not meet the IDNA BiDi requirements (for right-to-left characters)',
IDNA_ERROR_CONTEXTJ => 'a label does not meet the IDNA CONTEXTJ requirements',
];

$res = [];
foreach (self::IDNA_ERRORS as $error => $reason) {
foreach ($idnErrors as $error => $reason) {
if ($error === ($error_byte & $error)) {
$res[] = $reason;
}
Expand Down

0 comments on commit 450e4db

Please sign in to comment.