From 37ca6f0f9a0040b6dc2d5f108cebaa4f7f6abced Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Thu, 17 Nov 2022 23:55:26 +0100
Subject: [PATCH] url: move back the IDN conversion of proxy names

Regression: in commit 53bcf55 we moved the IDN conversion calls to
happen before the HSTS checks. But the HSTS checks are only done on the
server host name, not the proxy names. By moving the proxy name IDN
conversions, we accidentally broke the verbose output showing the proxy
name.

This change moves back the IDN conversions for the proxy names to the
place in the code path they were before 53bcf55.

Reported-by: Andy Stamp
Fixes #9937
Closes #9939

Conflict: NA
Reference: https://github.com/curl/curl/commit/37ca6f0f9a0040b6dc2d5f108cebaa4f7f6abced
---
 lib/url.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/lib/url.c b/lib/url.c
index f2ad31742..78f01c442 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2060,18 +2060,6 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
     if(result)
       return result;
   }
-#ifndef CURL_DISABLE_PROXY
-  if(conn->bits.httpproxy) {
-    result = Curl_idnconvert_hostname(data, &conn->http_proxy.host);
-    if(result)
-      return result;
-  }
-  if(conn->bits.socksproxy) {
-    result = Curl_idnconvert_hostname(data, &conn->socks_proxy.host);
-    if(result)
-      return result;
-  }
-#endif
 
 #ifndef CURL_DISABLE_HSTS
   /* HSTS upgrade */
@@ -3731,6 +3719,21 @@ static CURLcode create_conn(struct Curl_easy *data,
   if(result)
     goto out;
 
+  /*************************************************************
+   * IDN-convert the proxy hostnames
+   *************************************************************/
+#ifndef CURL_DISABLE_PROXY
+  if(conn->bits.httpproxy) {
+    result = Curl_idnconvert_hostname(data, &conn->http_proxy.host);
+    if(result)
+      return result;
+  }
+  if(conn->bits.socksproxy) {
+    result = Curl_idnconvert_hostname(data, &conn->socks_proxy.host);
+    if(result)
+      return result;
+  }
+#endif
 
   /*************************************************************
    * Check whether the host and the "connect to host" are equal.
-- 
2.33.0

