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 string to 2048 bytes for security reasons. | 12 // We limit the maximum length of string to 2048 bytes for security reasons. |
13 static const int maxiumStringLength = 2048; | 13 static const int maxiumStringLength = 2048; |
14 | 14 |
15 bool PaymentsValidators::isValidCurrencyCodeFormat( | 15 bool PaymentsValidators::isValidCurrencyCodeFormat( |
16 const String& code, | 16 const String& code, |
| 17 const String& system, |
17 String* optionalErrorMessage) { | 18 String* optionalErrorMessage) { |
| 19 if (system == "urn:iso:std:iso:4217") { |
| 20 if (ScriptRegexp("^[A-Z]{3}$", TextCaseSensitive).match(code) == 0) |
| 21 return true; |
| 22 |
| 23 if (optionalErrorMessage) |
| 24 *optionalErrorMessage = "'" + code + |
| 25 "' is not a valid ISO 4217 currency code, should " |
| 26 "be 3 upper case letters [A-Z]"; |
| 27 |
| 28 return false; |
| 29 } |
| 30 |
| 31 if (!KURL(KURL(), system).isValid()) { |
| 32 if (optionalErrorMessage) |
| 33 *optionalErrorMessage = "The currency system is not a valid URL"; |
| 34 |
| 35 return false; |
| 36 } |
| 37 |
18 if (code.length() <= maxiumStringLength) | 38 if (code.length() <= maxiumStringLength) |
19 return true; | 39 return true; |
20 | 40 |
21 if (optionalErrorMessage) | 41 if (optionalErrorMessage) |
22 *optionalErrorMessage = | 42 *optionalErrorMessage = |
23 "The currency code should be at most 2048 characters long"; | 43 "The currency code should be at most 2048 characters long"; |
24 | 44 |
25 return false; | 45 return false; |
26 } | 46 } |
27 | 47 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 return true; | 128 return true; |
109 | 129 |
110 if (optionalErrorMessage) | 130 if (optionalErrorMessage) |
111 *optionalErrorMessage = | 131 *optionalErrorMessage = |
112 "Error message should be at most 2048 characters long"; | 132 "Error message should be at most 2048 characters long"; |
113 | 133 |
114 return false; | 134 return false; |
115 } | 135 } |
116 | 136 |
117 } // namespace blink | 137 } // namespace blink |
OLD | NEW |