diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-23 18:04:01 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-23 18:04:01 +0000 |
commit | 0238de41ca1bdce286ac08d21c7634c36787ad7f (patch) | |
tree | fbdbdd2d5e0b3bfb4be2b6cd0e48d2ceaf8d1aa7 /net/proxy/proxy_resolver_v8.cc | |
parent | f2bd5397e9dbc5954aa78eef1ae9fed0f599650f (diff) | |
download | chromium_src-0238de41ca1bdce286ac08d21c7634c36787ad7f.zip chromium_src-0238de41ca1bdce286ac08d21c7634c36787ad7f.tar.gz chromium_src-0238de41ca1bdce286ac08d21c7634c36787ad7f.tar.bz2 |
Add support for international domain names in PAC scripts. This converts non-ASCII hostnames in dnsResolve() and dnsResolveEx() to punycode.
BUG=47234
TEST=ProxyResolverV8Test.DNSResolutionOfInternationDomainName
Review URL: http://codereview.chromium.org/2842017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50624 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_resolver_v8.cc')
-rw-r--r-- | net/proxy/proxy_resolver_v8.cc | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc index 05f16e9..4b54cb7 100644 --- a/net/proxy/proxy_resolver_v8.cc +++ b/net/proxy/proxy_resolver_v8.cc @@ -6,7 +6,9 @@ #include "base/logging.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "googleurl/src/gurl.h" +#include "googleurl/src/url_canon.h" #include "net/base/host_cache.h" #include "net/base/net_errors.h" #include "net/base/net_log.h" @@ -109,13 +111,30 @@ bool GetHostnameArgument(const v8::Arguments& args, std::string* hostname) { const string16 hostname_utf16 = V8StringToUTF16(args[0]->ToString()); - // TODO(eroman): Convert international domain names to punycode. Right - // now we fail if the hostname isn't entered in ASCII. - // crbug.com/47234 - if (!IsStringASCII(hostname_utf16)) + // If the hostname is already in ASCII, simply return it as is. + if (IsStringASCII(hostname_utf16)) { + *hostname = UTF16ToASCII(hostname_utf16); + return true; + } + + // Otherwise try to convert it from IDN to punycode. + const int kInitialBufferSize = 256; + url_canon::RawCanonOutputT<char16, kInitialBufferSize> punycode_output; + if (!url_canon::IDNToASCII(hostname_utf16.data(), + hostname_utf16.length(), + &punycode_output)) { return false; - *hostname = UTF16ToASCII(hostname_utf16); - return true; + } + + // |punycode_output| should now be ASCII; convert it to a std::string. + // (We could use UTF16ToASCII() instead, but that requires an extra string + // copy. Since ASCII is a subset of UTF8 the following is equivalent). + bool success = UTF16ToUTF8(punycode_output.data(), + punycode_output.length(), + hostname); + DCHECK(success); + DCHECK(IsStringASCII(*hostname)); + return success; } } // namespace |