Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: net/base/net_util.cc

Issue 1574034: Changes FormatURL to not strip http if the host starts with ftp or https[!a-z]. This... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <unicode/ucnv.h> 9 #include <unicode/ucnv.h>
10 #include <unicode/uidna.h> 10 #include <unicode/uidna.h>
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 std::wstring FormatUrl(const GURL& url, 1385 std::wstring FormatUrl(const GURL& url,
1386 const std::wstring& languages, 1386 const std::wstring& languages,
1387 FormatUrlTypes format_types, 1387 FormatUrlTypes format_types,
1388 UnescapeRule::Type unescape_rules, 1388 UnescapeRule::Type unescape_rules,
1389 url_parse::Parsed* new_parsed, 1389 url_parse::Parsed* new_parsed,
1390 size_t* prefix_end, 1390 size_t* prefix_end,
1391 size_t* offset_for_adjustment) { 1391 size_t* offset_for_adjustment) {
1392 url_parse::Parsed parsed_temp; 1392 url_parse::Parsed parsed_temp;
1393 if (!new_parsed) 1393 if (!new_parsed)
1394 new_parsed = &parsed_temp; 1394 new_parsed = &parsed_temp;
1395 else
1396 *new_parsed = url_parse::Parsed();
1395 size_t offset_temp = std::wstring::npos; 1397 size_t offset_temp = std::wstring::npos;
1396 if (!offset_for_adjustment) 1398 if (!offset_for_adjustment)
1397 offset_for_adjustment = &offset_temp; 1399 offset_for_adjustment = &offset_temp;
1398 1400
1399 std::wstring url_string; 1401 std::wstring url_string;
1400 1402
1401 // Check for empty URLs or 0 available text width. 1403 // Check for empty URLs or 0 available text width.
1402 if (url.is_empty()) { 1404 if (url.is_empty()) {
1403 if (prefix_end) 1405 if (prefix_end)
1404 *prefix_end = 0; 1406 *prefix_end = 0;
(...skipping 20 matching lines...) Expand all
1425 *offset_for_adjustment = std::wstring::npos; 1427 *offset_for_adjustment = std::wstring::npos;
1426 1428
1427 // Copy everything before the username (the scheme and the separators.) 1429 // Copy everything before the username (the scheme and the separators.)
1428 // These are ASCII. 1430 // These are ASCII.
1429 std::copy(spec.begin(), 1431 std::copy(spec.begin(),
1430 spec.begin() + parsed.CountCharactersBefore(url_parse::Parsed::USERNAME, 1432 spec.begin() + parsed.CountCharactersBefore(url_parse::Parsed::USERNAME,
1431 true), 1433 true),
1432 std::back_inserter(url_string)); 1434 std::back_inserter(url_string));
1433 1435
1434 const wchar_t* const kHTTP = L"http://"; 1436 const wchar_t* const kHTTP = L"http://";
1437 const char* const kFTP = "ftp.";
1435 const size_t kHTTPSize = std::wstring(kHTTP).size(); 1438 const size_t kHTTPSize = std::wstring(kHTTP).size();
1436 bool omit_http = ((format_types & kFormatUrlOmitHTTP) != 0 && 1439 // The omnibox treats ftp.foo.com as ftp://foo.com. This means that if we
1437 url_string == kHTTP); 1440 // trimmed http off a string that starts with http://ftp and the user tried to
1441 // reload the page the user would end up with a scheme of ftp://. For example,
1442 // 'http://ftp.foo.com' -> 'ftp.foo.com' -> 'ftp://foo.com'. For this reason
1443 // don't strip http off url's whose scheme is http and the host starts with
1444 // 'ftp.'.
1445 bool omit_http =
1446 ((format_types & kFormatUrlOmitHTTP) != 0 &&
1447 url_string == kHTTP && (!parsed.host.is_valid() ||
1448 (parsed.host.is_nonempty() &&
1449 spec.compare(parsed.host.begin,
1450 std::string(kFTP).size(), kFTP))));
1438 1451
1439 new_parsed->scheme = parsed.scheme; 1452 new_parsed->scheme = parsed.scheme;
1440 1453
1441 if ((format_types & kFormatUrlOmitUsernamePassword) != 0) { 1454 if ((format_types & kFormatUrlOmitUsernamePassword) != 0) {
1442 // Remove the username and password fields. We don't want to display those 1455 // Remove the username and password fields. We don't want to display those
1443 // to the user since they can be used for attacks, 1456 // to the user since they can be used for attacks,
1444 // e.g. "http://google.com:search@evil.ru/" 1457 // e.g. "http://google.com:search@evil.ru/"
1445 new_parsed->username.reset(); 1458 new_parsed->username.reset();
1446 new_parsed->password.reset(); 1459 new_parsed->password.reset();
1447 if ((*offset_for_adjustment != std::wstring::npos) && 1460 if ((*offset_for_adjustment != std::wstring::npos) &&
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 1732
1720 IPv6SupportResults(IPV6_GLOBAL_ADDRESS_MISSING); 1733 IPv6SupportResults(IPV6_GLOBAL_ADDRESS_MISSING);
1721 return false; 1734 return false;
1722 #else 1735 #else
1723 NOTIMPLEMENTED(); 1736 NOTIMPLEMENTED();
1724 return true; 1737 return true;
1725 #endif // defined(various platforms) 1738 #endif // defined(various platforms)
1726 } 1739 }
1727 1740
1728 } // namespace net 1741 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698