Browse Source

Don't include non-alphanumeric chars in hostnames.

Fixes plexinc/plex-media-player-private#533
Tobias Hieta 8 years ago
parent
commit
263174b471
3 changed files with 20 additions and 1 deletions
  1. 2 1
      src/remote/RemoteComponent.cpp
  2. 17 0
      src/utils/Utils.cpp
  3. 1 0
      src/utils/Utils.h

+ 2 - 1
src/remote/RemoteComponent.cpp

@@ -92,7 +92,8 @@ QVariantMap RemoteComponent::ResourceInformation()
 QVariantMap RemoteComponent::GDMInformation()
 {
   QVariantMap headers = {
-    {"Name", Utils::ComputerName()},
+    {"Name", Utils::sanitizeForHttpSeparators(Utils::ComputerName())},
+    {"RawName", Utils::ComputerName()},
     {"Port", SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "webserverport")},
     {"Version", Version::GetVersionString()},
     {"Product", "Plex Media Player"},

+ 17 - 0
src/utils/Utils.cpp

@@ -18,6 +18,23 @@
 
 #include "QsLog.h"
 
+QList<QChar> httpSeparators = { '(', ')', '<', '>', '@', ',', ';', ':', '\\', '\"', '/', '[', ']', '?', '=', '{', '}' };
+
+/////////////////////////////////////////////////////////////////////////////////////////
+QString Utils::sanitizeForHttpSeparators(const QString& input)
+{
+  auto output = input;
+
+  for (const QChar& c : httpSeparators)
+    output.replace(c, "");
+
+  for (int i = 0; i < output.size(); i ++)
+  {
+    if (!isalnum(output.at(i).toLatin1()))
+      output[i] = '_';
+  }
+  return output;
+}
 
 /////////////////////////////////////////////////////////////////////////////////////////
 QString Utils::ComputerName()

+ 1 - 0
src/utils/Utils.h

@@ -58,6 +58,7 @@ namespace Utils
   QString PrimaryIPv4Address();
   QString ClientUUID();
   bool safelyWriteFile(const QString& filename, const QByteArray& data);
+  QString sanitizeForHttpSeparators(const QString& input);
 }
 
 #endif // UTILS_H