@@ -67,14 +67,48 @@ public function __construct($uri = '')
6767    {
6868        // weak type check to also accept null until we can add scalar type hints 
6969        if  ($ uri'' ) {
70-             $ partsparse_url ($ uri
70+             $ partsself :: parse ($ uri
7171            if  ($ partsfalse ) {
7272                throw  new  \InvalidArgumentException ("Unable to parse URI:  $ uri );
7373            }
7474            $ this applyParts ($ parts
7575        }
7676    }
7777
78+     /** 
79+      * UTF-8 aware \parse_url() replacement. 
80+      * 
81+      * The internal function produces broken output for non ASCII domain names 
82+      * (IDN) when used with locales other than "C". 
83+      * 
84+      * On the other hand, cURL understands IDN correctly only when UTF-8 locale 
85+      * is configured ("C.UTF-8", "en_US.UTF-8", etc.). 
86+      * 
87+      * @see https://bugs.php.net/bug.php?id=52923 
88+      * @see https://www.php.net/manual/en/function.parse-url.php#114817 
89+      * @see https://curl.haxx.se/libcurl/c/CURLOPT_URL.html#ENCODING 
90+      * 
91+      * @return array|false 
92+      */ 
93+     private  static  function  parse ($ url$ component1 )
94+     {
95+         $ encodedUrlpreg_replace_callback (
96+             '%[^:/@?&=#]+%usD ' ,
97+             static  function  ($ matches
98+                 return  urlencode ($ matches0 ]);
99+             },
100+             $ url
101+         );
102+ 
103+         $ resultparse_url ($ encodedUrl$ component
104+ 
105+         if  ($ resultfalse ) {
106+             return  false ;
107+         }
108+ 
109+         return  is_array ($ resultarray_map ('urldecode ' , $ resulturldecode ($ result
110+     }
111+ 
78112    public  function  __toString ()
79113    {
80114        return  self ::composeComponents (
@@ -582,7 +616,7 @@ private function filterScheme($scheme)
582616            throw  new  \InvalidArgumentException ('Scheme must be a string ' );
583617        }
584618
585-         return  strtolower ($ scheme
619+         return  \strtr ($ scheme,  ' ABCDEFGHIJKLMNOPQRSTUVWXYZ ' ,  ' abcdefghijklmnopqrstuvwxyz ' 
586620    }
587621
588622    /** 
@@ -618,7 +652,7 @@ private function filterHost($host)
618652            throw  new  \InvalidArgumentException ('Host must be a string ' );
619653        }
620654
621-         return  strtolower ($ host
655+         return  \strtr ($ host,  ' ABCDEFGHIJKLMNOPQRSTUVWXYZ ' ,  ' abcdefghijklmnopqrstuvwxyz ' 
622656    }
623657
624658    /** 
0 commit comments