Commit 911a834f authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

scanning: Replace colons in instance name

Replace the colons in the scanner's instance name to prevent them from
breaking sane-airscan's device name parsing logic.

Bug: b:170976627
Change-Id: Ia62b200a6699f59b9fc55935c2ab9956279869ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2476517Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817669}
parent 49068326
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <string> #include <string>
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/chromeos/scanning/zeroconf_scanner_detector.h" #include "chrome/browser/chromeos/scanning/zeroconf_scanner_detector.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -44,6 +45,11 @@ std::string CreateDeviceName(const std::string& name, ...@@ -44,6 +45,11 @@ std::string CreateDeviceName(const std::string& name,
else if (!rs.empty()) else if (!rs.empty())
path = rs + "/"; path = rs + "/";
// Replace colons in the instance name to prevent them from breaking
// sane-airscan's device name parsing logic.
std::string sanitized_name;
base::ReplaceChars(name, ":", "-", &sanitized_name);
const std::string ip_address_str = const std::string ip_address_str =
ip_address.IsIPv6() ip_address.IsIPv6()
? base::StringPrintf("[%s]", ip_address.ToString().c_str()) ? base::StringPrintf("[%s]", ip_address.ToString().c_str())
...@@ -56,7 +62,7 @@ std::string CreateDeviceName(const std::string& name, ...@@ -56,7 +62,7 @@ std::string CreateDeviceName(const std::string& name,
return ""; return "";
} }
return base::StringPrintf("airscan:escl:%s:%s", name.c_str(), return base::StringPrintf("airscan:escl:%s:%s", sanitized_name.c_str(),
url.spec().c_str()); url.spec().c_str());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment