mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-24 14:29:27 +00:00
Fix #505: Allow requests with Cyrillic characters in url
This commit is contained in:
@@ -150,6 +150,33 @@ class Url
|
||||
*/
|
||||
private function parseUrl($url)
|
||||
{
|
||||
// ALPHA = A-Z / a-z
|
||||
$alpha = 'A-Za-z';
|
||||
|
||||
// DIGIT = 0-9
|
||||
$digit = '0-9';
|
||||
|
||||
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
$unreserved = $alpha . $digit . preg_quote('-._~');
|
||||
|
||||
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||
// / "*" / "+" / "," / ";" / "="
|
||||
$sub_delims = preg_quote('!$&\'()*+,;=');
|
||||
|
||||
// HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
|
||||
$hexdig = $digit . 'A-F';
|
||||
// "The uppercase hexadecimal digits 'A' through 'F' are equivalent to
|
||||
// the lowercase digits 'a' through 'f', respectively."
|
||||
$hexdig .= 'a-f';
|
||||
|
||||
$pattern = '/(?:[^' . $unreserved . $sub_delims . preg_quote(':@%/?', '/') . ']++|%(?![' . $hexdig . ']{2}))/';
|
||||
$url = preg_replace_callback(
|
||||
$pattern,
|
||||
function ($matches) {
|
||||
return rawurlencode($matches[0]);
|
||||
},
|
||||
$url
|
||||
);
|
||||
return parse_url($url);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,4 +108,13 @@ class UrlTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEquals($test['expected'], $actual_path);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCyrillicChars()
|
||||
{
|
||||
$path_part = 'Банан-комнатный-саженцы-банана';
|
||||
$original_url = 'https://www.example.com/path/' . $path_part . '/page.html';
|
||||
$expected_url = 'https://www.example.com/path/' . rawurlencode($path_part) . '/page.html';
|
||||
$url = new Url($original_url);
|
||||
$this->assertEquals($expected_url, $url);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user