Chromium Code Reviews| 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 KURL currencySystemUrl = KURL(KURL(), system); | |
| 20 if (!currencySystemUrl.isValid()) { | |
|
please use gerrit instead
2016/10/12 23:35:50
Inline "currencySystemUrl":
if (!KURL(KURL(), sys
pals
2016/10/13 09:30:38
Done.
| |
| 21 if (optionalErrorMessage) { | |
|
please use gerrit instead
2016/10/12 23:35:49
Let's use {} in the same way as the rest of the fi
pals
2016/10/13 09:30:38
Done.
| |
| 22 *optionalErrorMessage = "The currency system is not a valid url"; | |
| 23 } | |
| 24 | |
| 25 return false; | |
| 26 } | |
| 27 | |
| 28 if (system == "urn:iso:std:iso:4217") { | |
|
please use gerrit instead
2016/10/12 23:35:50
This is a URN, which is different from URL. Theref
pals
2016/10/13 09:30:38
Done.
| |
| 29 if (ScriptRegexp("^[A-Z]{3}$", TextCaseSensitive).match(code) == 0) | |
| 30 return true; | |
| 31 | |
| 32 if (optionalErrorMessage) { | |
|
please use gerrit instead
2016/10/12 23:35:50
No need for {}
pals
2016/10/13 09:30:38
Done.
| |
| 33 *optionalErrorMessage = | |
| 34 "'" + code + | |
| 35 "' is not a valid ISO 4217 " | |
| 36 "currency code, should be 3 upper case letters [A-Z]"; | |
| 37 } | |
| 38 | |
| 39 return false; | |
| 40 } | |
| 41 | |
| 18 if (code.length() <= maxiumStringLength) | 42 if (code.length() <= maxiumStringLength) |
| 19 return true; | 43 return true; |
| 20 | 44 |
| 21 if (optionalErrorMessage) | 45 if (optionalErrorMessage) |
| 22 *optionalErrorMessage = | 46 *optionalErrorMessage = |
| 23 "The currency code should be at most 2048 characters long"; | 47 "The currency code should be at most 2048 characters long"; |
| 24 | 48 |
| 25 return false; | 49 return false; |
| 26 } | 50 } |
| 27 | 51 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 return true; | 132 return true; |
| 109 | 133 |
| 110 if (optionalErrorMessage) | 134 if (optionalErrorMessage) |
| 111 *optionalErrorMessage = | 135 *optionalErrorMessage = |
| 112 "Error message should be at most 2048 characters long"; | 136 "Error message should be at most 2048 characters long"; |
| 113 | 137 |
| 114 return false; | 138 return false; |
| 115 } | 139 } |
| 116 | 140 |
| 117 } // namespace blink | 141 } // namespace blink |
| OLD | NEW |