Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: components/payments/payments_validators.cc

Issue 2373103002: [Web Payments] Common Payments validation (Closed)
Patch Set: Deps and new field Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "components/payments/payments_validators.h"
6
7 #include "third_party/re2/src/re2/re2.h"
8
9 namespace payments {
10
11 // We limit the maximum length of the currency code to 2048 bytes for security
12 // reasons.
13 static const int maxCurrencyCodeLength = 2048;
14
15 bool PaymentsValidators::isValidCurrencyCodeFormat(
16 const std::string& code,
17 const std::string& system,
18 std::string* optionalErrorMessage) {
19 if (system == "urn:iso:std:iso:4217") {
20 if (RE2::FullMatch(code, "[A-Z]{3}"))
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 (code.size() <= maxCurrencyCodeLength)
32 return true;
33
34 if (optionalErrorMessage)
35 *optionalErrorMessage =
36 "The currency code should be at most 2048 characters long";
37
38 return false;
39 }
40
41 bool PaymentsValidators::isValidAmountFormat(
42 const std::string& amount,
43 std::string* optionalErrorMessage) {
44 if (RE2::FullMatch(amount, "-?[0-9]+(\\.[0-9]+)?"))
45 return true;
46
47 if (optionalErrorMessage)
48 *optionalErrorMessage = "'" + amount + "' is not a valid amount format";
49
50 return false;
51 }
52
53 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698