-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use symfony/polyfill-mbstring to correct issues in Hostname vali…
…dator This patch adds symfony/polyfill-mbstring as a requirement, and updates the `Hostname` validator to use mbstring equivalents of various string operations, where they are available. Locally, one of the two new tests passes, but one original test ("UTF-8 label + UTF-8 TLD (cyrillic)") now fails — which may be a problem with my own locale. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
- Loading branch information
1 parent
ac7fe2e
commit ebaa162
Showing
3 changed files
with
97 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1995,8 +1995,8 @@ public function isValid($value) | |
$this->setValue($value); | ||
// Check input against IP address schema | ||
if ( | ||
((preg_match('/^[0-9.]*$/', $value) && strpos($value, '.') !== false) | ||
|| (preg_match('/^[0-9a-f:.]*$/i', $value) && strpos($value, ':') !== false)) | ||
((preg_match('/^[0-9.]*$/', $value) && mb_strpos($value, '.') !== false) | ||
|| (preg_match('/^[0-9a-f:.]*$/i', $value) && mb_strpos($value, ':') !== false)) | ||
&& $this->getIpValidator()->setTranslator($this->getTranslator())->isValid($value) | ||
) { | ||
if (! ($this->getAllow() & self::ALLOW_IP)) { | ||
|
@@ -2010,16 +2010,16 @@ public function isValid($value) | |
// Handle Regex compilation failure that may happen on .biz domain with has @ character, eg: [email protected] | ||
// Technically, hostname with '@' character is invalid, so mark as invalid immediately | ||
// @see https://github.com/laminas/laminas-validator/issues/8 | ||
if (strpos($value, '@') !== false) { | ||
if (mb_strpos($value, '@') !== false) { | ||
$this->error(self::INVALID_HOSTNAME); | ||
return false; | ||
} | ||
|
||
// Local hostnames are allowed to be partial (ending '.') | ||
if ($this->getAllow() & self::ALLOW_LOCAL) { | ||
if (substr($value, -1) === '.') { | ||
$value = substr($value, 0, -1); | ||
if (substr($value, -1) === '.') { | ||
if (mb_substr($value, -1) === '.') { | ||
$value = mb_substr($value, 0, -1); | ||
if (mb_substr($value, -1) === '.') { | ||
// Empty hostnames (ending '..') are not allowed | ||
$this->error(self::INVALID_LOCAL_NAME); | ||
return false; | ||
|
@@ -2063,20 +2063,20 @@ public function isValid($value) | |
|
||
$this->tld = $matches[1]; | ||
// Decode Punycode TLD to IDN | ||
if (strpos($this->tld, 'xn--') === 0) { | ||
$this->tld = $this->decodePunycode(substr($this->tld, 4)); | ||
if (mb_strpos($this->tld, 'xn--') === 0) { | ||
$this->tld = $this->decodePunycode(mb_substr($this->tld, 4)); | ||
if ($this->tld === false) { | ||
return false; | ||
} | ||
} else { | ||
$this->tld = strtoupper($this->tld); | ||
$this->tld = mb_strtoupper($this->tld); | ||
} | ||
|
||
// Match TLD against known list | ||
$removedTld = false; | ||
if ($this->getTldCheck()) { | ||
if ( | ||
! in_array(strtolower($this->tld), $this->validTlds) | ||
! in_array(mb_strtolower($this->tld), $this->validTlds) | ||
&& ! in_array($this->tld, $this->validTlds) | ||
) { | ||
$this->error(self::UNKNOWN_TLD); | ||
|
@@ -2112,8 +2112,8 @@ public function isValid($value) | |
} | ||
foreach ($domainParts as $domainPart) { | ||
// Decode Punycode domain names to IDN | ||
if (strpos($domainPart, 'xn--') === 0) { | ||
$domainPart = $this->decodePunycode(substr($domainPart, 4)); | ||
if (mb_strpos($domainPart, 'xn--') === 0) { | ||
$domainPart = $this->decodePunycode(mb_substr($domainPart, 4)); | ||
if ($domainPart === false) { | ||
return false; | ||
} | ||
|
@@ -2240,7 +2240,7 @@ protected function decodePunycode($encoded) | |
} | ||
|
||
$decoded = []; | ||
$separator = strrpos($encoded, '-'); | ||
$separator = mb_strrpos($encoded, '-'); | ||
if ($separator > 0) { | ||
for ($x = 0; $x < $separator; ++$x) { | ||
// prepare decoding matrix | ||
|
@@ -2249,7 +2249,7 @@ protected function decodePunycode($encoded) | |
} | ||
|
||
$lengthd = count($decoded); | ||
$lengthe = strlen($encoded); | ||
$lengthe = mb_strlen($encoded); | ||
|
||
// decoding | ||
$init = true; | ||
|