Do not copy to clipboard query parameters of mailto links via context menu.

The action is called copy "Copy email address".

Bug: 911139
Change-Id: I6e34803749898fedd008024ecba52d0ab1c11f19
Reviewed-on: https://chromium-review.googlesource.com/c/1472691
Reviewed-by: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632253}
diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
index 8d9616e..2ae0342a 100644
--- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc
+++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
@@ -747,9 +747,13 @@
   DCHECK(!url.is_empty());
   DCHECK(url.is_valid());
 
+  GURL url_to_format = url;
   url_formatter::FormatUrlTypes format_types;
   net::UnescapeRule::Type unescape_rules;
   if (url.SchemeIs(url::kMailToScheme)) {
+    GURL::Replacements replacements;
+    replacements.ClearQuery();
+    url_to_format = url.ReplaceComponents(replacements);
     format_types = url_formatter::kFormatUrlOmitMailToScheme;
     unescape_rules =
         net::UnescapeRule::PATH_SEPARATORS |
@@ -759,8 +763,8 @@
     unescape_rules = net::UnescapeRule::NONE;
   }
 
-  return url_formatter::FormatUrl(url, format_types, unescape_rules, nullptr,
-                                  nullptr, nullptr);
+  return url_formatter::FormatUrl(url_to_format, format_types, unescape_rules,
+                                  nullptr, nullptr, nullptr);
 }
 
 void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) {
diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc b/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc
index 8c6256e..e75bc62 100644
--- a/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc
+++ b/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc
@@ -690,6 +690,8 @@
     {"file://stuff.host.co/my%2Dshare/foo.txt",
      "file://stuff.host.co/my-share/foo.txt", "FileSafeUnescapes"},
     {"mailto:me@foo.com", "me@foo.com", "MailToNoEscapes"},
+    {"mailto:me@foo.com,you@bar.com?subject=Hello%20world",
+     "me@foo.com,you@bar.com", "MailToWithQuery"},
     {"mailto:me@%66%6F%6F.com", "me@foo.com", "MailToSafeEscapes"},
     {"mailto:me%2Bsorting-tag@foo.com", "me+sorting-tag@foo.com",
      "MailToEscapedSpecialCharacters"},