From 818271f075e6e0e779844920b608a9c07db430cc Mon Sep 17 00:00:00 2001 From: ignace namagana butera Date: Wed, 20 Nov 2019 08:12:26 +0100 Subject: [PATCH 1/2] remove intl requirement in Uri class --- src/Uri.php | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Uri.php b/src/Uri.php index 10ee18c7..ad6b6cf2 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -167,24 +167,6 @@ final class Uri implements UriInterface */ private const REGEXP_WINDOW_PATH = ',^(?[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. @@ -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; } From 233e016bbe4ae639373cfcd9dfae3950cd4a6df8 Mon Sep 17 00:00:00 2001 From: ignace namagana butera Date: Wed, 20 Nov 2019 20:36:13 +0100 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e212db87..6ec87711 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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