OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "modules/payments/ShippingAddress.h" | |
6 | |
7 namespace blink { | |
8 namespace { | |
9 | |
10 bool isValidRegionCodeString(const String& code) | |
groby-ooo-7-16
2016/03/18 00:47:26
Please add comments on what _kind_ of region codes
rwlbuis
2016/03/18 14:37:59
Why not make all three helpers static?
please use gerrit instead
2016/03/23 00:14:52
Done.
please use gerrit instead
2016/03/23 00:14:52
This comes from region_data_constants.cc in Chrome
| |
11 { | |
12 if (code.length() != 2) | |
13 return false; | |
14 | |
15 for (size_t i = 0; i < code.length(); ++i) { | |
groby-ooo-7-16
2016/03/18 00:47:25
I take it String doesn't have iterators, so no ran
please use gerrit instead
2016/03/23 00:14:52
That's right.
| |
16 if (code[i] < 'A' || code[i] > 'Z') | |
groby-ooo-7-16
2016/03/18 00:47:26
Probably isalpha() instead, unless there's a reaso
Marijn Kruisselbrink
2016/03/18 01:39:48
isASCIIUpper(), rather than isupper(). std::isuppe
please use gerrit instead
2016/03/23 00:14:52
Using ScriptRegexp instead.
please use gerrit instead
2016/03/23 00:14:52
Using ScriptRegexp instead.
| |
17 return false; | |
18 } | |
19 | |
20 return true; | |
21 } | |
22 | |
23 bool isValidLanguageCodeString(const String& code) | |
24 { | |
25 if (code.isEmpty()) | |
26 return true; | |
27 | |
28 if (code.length() != 2 && code.length() != 3) | |
groby-ooo-7-16
2016/03/18 00:47:26
ISO639, I take it? (Although, again, that would al
please use gerrit instead
2016/03/23 00:14:52
This comes from region_data_constants.cc in Chrome
| |
29 return false; | |
30 | |
31 for (size_t i = 0; i < code.length(); ++i) { | |
32 if (code[i] < 'a' || code[i] > 'z') | |
groby-ooo-7-16
2016/03/18 00:47:26
islower
Marijn Kruisselbrink
2016/03/18 01:39:48
isASCIILower()
please use gerrit instead
2016/03/23 00:14:52
Using ScriptRegexp instead.
please use gerrit instead
2016/03/23 00:14:52
Using ScriptRegexp instead.
| |
33 return false; | |
34 } | |
35 | |
36 return true; | |
37 } | |
38 | |
39 bool isValidScriptCodeString(const String& code) | |
groby-ooo-7-16
2016/03/18 00:47:26
ISO 15924 ?
please use gerrit instead
2016/03/23 00:14:52
Added comments and error message strings that spec
| |
40 { | |
41 if (code.isEmpty()) | |
42 return true; | |
43 | |
44 if (code.length() != 4) | |
45 return false; | |
46 | |
47 if (code[0] < 'A' || code[0] > 'A') | |
groby-ooo-7-16
2016/03/18 00:47:25
Technically, that's again isalpha for all 4.
Marijn Kruisselbrink
2016/03/18 01:39:48
I assume you didn't mean to write "if (code[0] !=
please use gerrit instead
2016/03/23 00:14:52
Using ScriptRegexp instead.
please use gerrit instead
2016/03/23 00:14:52
Fixed, tested in PaymentsValidatorsTest.cpp, and s
| |
48 return false; | |
49 | |
50 for (size_t i = 1; i < code.length(); ++i) { | |
51 if (code[i] < 'a' || code[i] > 'z') | |
52 return false; | |
53 } | |
54 | |
55 return true; | |
56 } | |
57 | |
58 } // namespace | |
59 | |
60 ShippingAddress::ShippingAddress(mojom::blink::ShippingAddressPtr address) | |
61 : m_regionCode(address->region_code) | |
62 , m_addressLine(address->address_line.PassStorage()) | |
63 , m_administrativeArea(address->administrative_area) | |
64 , m_locality(address->locality) | |
65 , m_dependentLocality(address->dependent_locality) | |
66 , m_postalCode(address->postal_code) | |
67 , m_sortingCode(address->sorting_code) | |
68 , m_languageCode(address->language_code) | |
69 , m_organization(address->organization) | |
70 , m_recipient(address->recipient) | |
71 , m_validRegionCode(isValidRegionCodeString(address->region_code)) | |
groby-ooo-7-16
2016/03/18 00:47:26
Assuming we're doing the validation for security r
please use gerrit instead
2016/03/23 00:14:52
Moved validation to PaymentRequest::onShippingAddr
| |
72 , m_validLanguageCode(isValidLanguageCodeString(address->language_code)) | |
73 , m_validScriptCode(isValidScriptCodeString(address->script_code)) | |
74 { | |
75 if (!m_languageCode.isEmpty() && !address->script_code.isEmpty()) { | |
76 m_languageCode.append("-"); | |
77 m_languageCode.append(address->script_code); | |
78 } | |
79 } | |
80 | |
81 ShippingAddress::~ShippingAddress() {} | |
82 | |
83 } // namespace blink | |
OLD | NEW |