Skip to content

fyi - punycode of URI #1

@mrgleeco

Description

@mrgleeco

hi there - noticed that if the IDN hostname is also in the URI, it also gets encoded.
example/test:

https://палочка.ru/foo+палочка+bar
enc-> https://xn--80aa3adpd3d.ru/foo+xn--80aa3adpd3d+bar
dec-> https://палочка.ru/foo+палочка+bar

While the decode does do the proper thing, the encoded value will be broken. Simple fix to limit to host:

     private static function urlendecode($url, $func) {
         $uri = parse_url($url);
+        $mod = FALSE;
         if (!empty($uri['host'])) {
             foreach (array_unique((array)explode('.', $uri['host'])) as $var) {
                 if (($encoded = self::$func($var)) != $var) {
-                    $url = str_replace($var, $encoded, $url);
+                    $uri['host'] = str_replace($var, $encoded, $uri['host']);
+                    $mod = TRUE;
                 }
             }
+            // rebuild the URL from parsed parts
+            if ($mod) $url = http_build_url($uri);
         }
         return $url;
     }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions