Chromium Code Reviews| Index: components/payments/payments_validators.cc |
| diff --git a/components/payments/payments_validators.cc b/components/payments/payments_validators.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2d4d401e6f1428474df7ec47f65c16ee6613243b |
| --- /dev/null |
| +++ b/components/payments/payments_validators.cc |
| @@ -0,0 +1,39 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/payments/payments_validators.h" |
| + |
| +namespace payments { |
| + |
| +// We limit the maximum length of the currency code to 2048 bytes for security |
| +// reasons. |
| +static const int maxCurrencyCodeLength = 2048; |
| + |
| +bool PaymentsValidators::isValidCurrencyCodeFormat( |
| + const std::string& code, |
| + std::string* optionalErrorMessage) { |
| + if (code.size() <= maxCurrencyCodeLength) |
| + return true; |
| + |
| + if (optionalErrorMessage) |
| + *optionalErrorMessage = |
| + "The currency code should be at most 2048 characters long"; |
| + |
| + return false; |
| +} |
| + |
| +bool PaymentsValidators::isValidAmountFormat( |
| + const std::string& amount, |
| + std::string* optionalErrorMessage) { |
| + // if (ScriptRegexp("^-?[0-9]+(\\.[0-9]+)?$", |
|
please use gerrit instead
2016/10/28 18:38:58
Can you use https://cs.chromium.org/chromium/src/t
Kevin Bailey
2016/10/28 20:53:05
Done. (Sorry if I nuked it.) But there was a probl
please use gerrit instead
2016/10/31 13:17:33
Seems that "re2" dependency was added to component
Kevin Bailey
2016/10/31 14:10:03
Ya, it required the full path.
|
| + // TextCaseSensitive).match(amount) == 0) |
| + // return true; |
| + |
| + if (optionalErrorMessage) |
| + *optionalErrorMessage = "'" + amount + "' is not a valid amount format"; |
| + |
| + return false; |
| +} |
| + |
| +} // namespace payments |