diff --git a/src/uri.cpp b/src/uri.cpp
index 4a4f6b2ac39356e541caa2ed71f39f392274c93a..6e0748f65df8f9ea866fdc99e1ba11ab3da16b1f 100644
--- a/src/uri.cpp
+++ b/src/uri.cpp
@@ -516,7 +516,7 @@ QString URI::format(FlagPack<URI::Section> sections) const
    if (sections & URI::Section::USER_INFO)
       ret += d_ptr->m_Userinfo;
 
-   if (sections & URI::Section::HOSTNAME)
+   if (sections & URI::Section::HOSTNAME && !d_ptr->m_Hostname2.isEmpty())
       ret += '@' + d_ptr->m_Hostname2;
 
    if (sections & URI::Section::PORT && d_ptr->m_Port != -1)