OLD | NEW |
1 /* | 1 /* |
2 * This file is part of the WebKit project. | 2 * This file is part of the WebKit project. |
3 * | 3 * |
4 * Copyright (C) 2009 Michelangelo De Simone <micdesim@gmail.com> | 4 * Copyright (C) 2009 Michelangelo De Simone <micdesim@gmail.com> |
5 * Copyright (C) 2010 Google Inc. All rights reserved. | 5 * Copyright (C) 2010 Google Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 * | 21 * |
22 */ | 22 */ |
23 | 23 |
24 #include "core/html/forms/EmailInputType.h" | 24 #include "core/html/forms/EmailInputType.h" |
25 | 25 |
| 26 #include <unicode/idna.h> |
| 27 #include <unicode/unistr.h> |
| 28 #include <unicode/uvernum.h> |
26 #include "bindings/core/v8/ScriptRegexp.h" | 29 #include "bindings/core/v8/ScriptRegexp.h" |
27 #include "core/InputTypeNames.h" | 30 #include "core/InputTypeNames.h" |
28 #include "core/html/HTMLInputElement.h" | 31 #include "core/html/HTMLInputElement.h" |
29 #include "core/html/parser/HTMLParserIdioms.h" | 32 #include "core/html/parser/HTMLParserIdioms.h" |
30 #include "core/page/ChromeClient.h" | 33 #include "core/page/ChromeClient.h" |
31 #include "platform/text/PlatformLocale.h" | 34 #include "platform/text/PlatformLocale.h" |
32 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
33 #include "wtf/text/StringBuilder.h" | 36 #include "wtf/text/StringBuilder.h" |
34 #include <unicode/idna.h> | 37 |
35 #include <unicode/unistr.h> | 38 #if U_ICU_VERSION_MAJOR_NUM >= 59 |
| 39 #include <unicode/char16ptr.h> |
| 40 #endif |
36 | 41 |
37 namespace blink { | 42 namespace blink { |
38 | 43 |
39 using blink::WebLocalizedString; | 44 using blink::WebLocalizedString; |
40 | 45 |
41 // http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-typ
e-attribute.html#valid-e-mail-address | 46 // http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-typ
e-attribute.html#valid-e-mail-address |
42 static const char localPartCharacters[] = | 47 static const char localPartCharacters[] = |
43 "abcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+/=?^_`{|}~.-"; | 48 "abcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+/=?^_`{|}~.-"; |
44 static const char emailPattern[] = | 49 static const char emailPattern[] = |
45 "[a-z0-9!#$%&'*+/=?^_`{|}~.-]+" // local part | 50 "[a-z0-9!#$%&'*+/=?^_`{|}~.-]+" // local part |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 icu::IDNA::createUTS46Instance(idnaConversionOption, errorCode); | 85 icu::IDNA::createUTS46Instance(idnaConversionOption, errorCode); |
81 DCHECK(idna); | 86 DCHECK(idna); |
82 icu::IDNAInfo idnaInfo; | 87 icu::IDNAInfo idnaInfo; |
83 idna->nameToASCII(idnDomainName, domainName, idnaInfo, errorCode); | 88 idna->nameToASCII(idnDomainName, domainName, idnaInfo, errorCode); |
84 if (U_FAILURE(errorCode) || idnaInfo.hasErrors() || | 89 if (U_FAILURE(errorCode) || idnaInfo.hasErrors() || |
85 domainName.length() > maximumDomainNameLength) | 90 domainName.length() > maximumDomainNameLength) |
86 return address; | 91 return address; |
87 | 92 |
88 StringBuilder builder; | 93 StringBuilder builder; |
89 builder.append(address, 0, atPosition + 1); | 94 builder.append(address, 0, atPosition + 1); |
| 95 #if U_ICU_VERSION_MAJOR_NUM >= 59 |
| 96 builder.append(icu::toUCharPtr(domainName.getBuffer()), domainName.length()); |
| 97 #else |
90 builder.append(domainName.getBuffer(), domainName.length()); | 98 builder.append(domainName.getBuffer(), domainName.length()); |
| 99 #endif |
91 String asciiEmail = builder.toString(); | 100 String asciiEmail = builder.toString(); |
92 return isValidEmailAddress(regexp, asciiEmail) ? asciiEmail : address; | 101 return isValidEmailAddress(regexp, asciiEmail) ? asciiEmail : address; |
93 } | 102 } |
94 | 103 |
95 String EmailInputType::convertEmailAddressToUnicode( | 104 String EmailInputType::convertEmailAddressToUnicode( |
96 const String& address) const { | 105 const String& address) const { |
97 if (!address.containsOnlyASCII()) | 106 if (!address.containsOnlyASCII()) |
98 return address; | 107 return address; |
99 | 108 |
100 size_t atPosition = address.find('@'); | 109 size_t atPosition = address.find('@'); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 builder.reserveCapacity(value.length()); | 312 builder.reserveCapacity(value.length()); |
304 for (size_t i = 0; i < addresses.size(); ++i) { | 313 for (size_t i = 0; i < addresses.size(); ++i) { |
305 if (i > 0) | 314 if (i > 0) |
306 builder.append(','); | 315 builder.append(','); |
307 builder.append(convertEmailAddressToUnicode(addresses[i])); | 316 builder.append(convertEmailAddressToUnicode(addresses[i])); |
308 } | 317 } |
309 return builder.toString(); | 318 return builder.toString(); |
310 } | 319 } |
311 | 320 |
312 } // namespace blink | 321 } // namespace blink |
OLD | NEW |