OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "modules/payments/PaymentsValidators.h" | 5 #include "modules/payments/PaymentsValidators.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptRegexp.h" | 7 #include "bindings/core/v8/ScriptRegexp.h" |
8 #include "wtf/text/StringImpl.h" | 8 #include "wtf/text/StringImpl.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
| 12 // We limit the maximum length of the currency code to 2048 bytes for security r
easons. |
| 13 static const int maxCurrencyCodeLength = 2048; |
| 14 |
12 bool PaymentsValidators::isValidCurrencyCodeFormat(const String& code, String* o
ptionalErrorMessage) | 15 bool PaymentsValidators::isValidCurrencyCodeFormat(const String& code, String* o
ptionalErrorMessage) |
13 { | 16 { |
14 if (ScriptRegexp("^[A-Z]{3}$", TextCaseSensitive).match(code) == 0) | 17 if (code.length() <= maxCurrencyCodeLength) |
15 return true; | 18 return true; |
16 | 19 |
17 if (optionalErrorMessage) | 20 if (optionalErrorMessage) |
18 *optionalErrorMessage = "'" + code + "' is not a valid ISO 4217 currency
code, should be 3 upper case letters [A-Z]"; | 21 *optionalErrorMessage = "The currency code should be at most 2048 charac
ters long"; |
19 | 22 |
20 return false; | 23 return false; |
21 } | 24 } |
22 | 25 |
23 bool PaymentsValidators::isValidAmountFormat(const String& amount, String* optio
nalErrorMessage) | 26 bool PaymentsValidators::isValidAmountFormat(const String& amount, String* optio
nalErrorMessage) |
24 { | 27 { |
25 if (ScriptRegexp("^-?[0-9]+(\\.[0-9]+)?$", TextCaseSensitive).match(amount)
== 0) | 28 if (ScriptRegexp("^-?[0-9]+(\\.[0-9]+)?$", TextCaseSensitive).match(amount)
== 0) |
26 return true; | 29 return true; |
27 | 30 |
28 if (optionalErrorMessage) | 31 if (optionalErrorMessage) |
29 *optionalErrorMessage = "'" + amount + "' is not a valid ISO 20022 Curre
ncyAnd30Amount"; | 32 *optionalErrorMessage = "'" + amount + "' is not a valid amount format"; |
30 | 33 |
31 return false; | 34 return false; |
32 } | 35 } |
33 | 36 |
34 bool PaymentsValidators::isValidCountryCodeFormat(const String& code, String* op
tionalErrorMessage) | 37 bool PaymentsValidators::isValidCountryCodeFormat(const String& code, String* op
tionalErrorMessage) |
35 { | 38 { |
36 if (ScriptRegexp("^[A-Z]{2}$", TextCaseSensitive).match(code) == 0) | 39 if (ScriptRegexp("^[A-Z]{2}$", TextCaseSensitive).match(code) == 0) |
37 return true; | 40 return true; |
38 | 41 |
39 if (optionalErrorMessage) | 42 if (optionalErrorMessage) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (optionalErrorMessage) | 82 if (optionalErrorMessage) |
80 *optionalErrorMessage = "If language code is empty, then script code
should also be empty"; | 83 *optionalErrorMessage = "If language code is empty, then script code
should also be empty"; |
81 | 84 |
82 return false; | 85 return false; |
83 } | 86 } |
84 | 87 |
85 return true; | 88 return true; |
86 } | 89 } |
87 | 90 |
88 } // namespace blink | 91 } // namespace blink |
OLD | NEW |