Chromium Code Reviews| Index: components/payments/payments_validators.cc |
| diff --git a/third_party/WebKit/Source/modules/payments/PaymentsValidators.cpp b/components/payments/payments_validators.cc |
| similarity index 59% |
| copy from third_party/WebKit/Source/modules/payments/PaymentsValidators.cpp |
| copy to components/payments/payments_validators.cc |
| index 5b9ddaab2a0f31267e017f5d1d663c13540b8fdd..3b3b386d315ae094fd90796f341c2ab0e9ae12c7 100644 |
| --- a/third_party/WebKit/Source/modules/payments/PaymentsValidators.cpp |
| +++ b/components/payments/payments_validators.cc |
| @@ -2,23 +2,21 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "modules/payments/PaymentsValidators.h" |
| +#include "components/payments/payments_validators.h" |
| -#include "bindings/core/v8/ScriptRegexp.h" |
| -#include "platform/weborigin/KURL.h" |
| -#include "wtf/text/StringImpl.h" |
| +#include "third_party/re2/src/re2/re2.h" |
| -namespace blink { |
| +namespace payments { |
| // We limit the maximum length of string to 2048 bytes for security reasons. |
| -static const int maxiumStringLength = 2048; |
| +static const int maximumStringLength = 2048; |
| bool PaymentsValidators::isValidCurrencyCodeFormat( |
| - const String& code, |
| - const String& system, |
| - String* optionalErrorMessage) { |
| + const std::string& code, |
| + const std::string& system, |
| + std::string* optionalErrorMessage) { |
| if (system == "urn:iso:std:iso:4217") { |
| - if (ScriptRegexp("^[A-Z]{3}$", TextCaseSensitive).match(code) == 0) |
| + if (RE2::FullMatch(code, "[A-Z]{3}")) |
| return true; |
| if (optionalErrorMessage) |
| @@ -29,14 +27,7 @@ bool PaymentsValidators::isValidCurrencyCodeFormat( |
| return false; |
| } |
| - if (!KURL(KURL(), system).isValid()) { |
| - if (optionalErrorMessage) |
| - *optionalErrorMessage = "The currency system is not a valid URL"; |
| - |
| - return false; |
| - } |
|
please use gerrit instead
2016/11/01 14:20:03
Let's not delete validating of "system". It should
Kevin Bailey
2016/11/01 15:32:13
Thank you for spotting that. I thought I had kept
|
| - |
| - if (code.length() <= maxiumStringLength) |
| + if (code.size() <= maximumStringLength) |
| return true; |
| if (optionalErrorMessage) |
| @@ -46,10 +37,10 @@ bool PaymentsValidators::isValidCurrencyCodeFormat( |
| return false; |
| } |
| -bool PaymentsValidators::isValidAmountFormat(const String& amount, |
| - String* optionalErrorMessage) { |
| - if (ScriptRegexp("^-?[0-9]+(\\.[0-9]+)?$", TextCaseSensitive).match(amount) == |
| - 0) |
| +bool PaymentsValidators::isValidAmountFormat( |
| + const std::string& amount, |
| + std::string* optionalErrorMessage) { |
| + if (RE2::FullMatch(amount, "-?[0-9]+(\\.[0-9]+)?")) |
| return true; |
| if (optionalErrorMessage) |
| @@ -59,9 +50,9 @@ bool PaymentsValidators::isValidAmountFormat(const String& amount, |
| } |
| bool PaymentsValidators::isValidCountryCodeFormat( |
| - const String& code, |
| - String* optionalErrorMessage) { |
| - if (ScriptRegexp("^[A-Z]{2}$", TextCaseSensitive).match(code) == 0) |
| + const std::string& code, |
| + std::string* optionalErrorMessage) { |
| + if (RE2::FullMatch(code, "[A-Z]{2}")) |
| return true; |
| if (optionalErrorMessage) |
| @@ -73,9 +64,9 @@ bool PaymentsValidators::isValidCountryCodeFormat( |
| } |
| bool PaymentsValidators::isValidLanguageCodeFormat( |
| - const String& code, |
| - String* optionalErrorMessage) { |
| - if (ScriptRegexp("^([a-z]{2,3})?$", TextCaseSensitive).match(code) == 0) |
| + const std::string& code, |
| + std::string* optionalErrorMessage) { |
| + if (RE2::FullMatch(code, "([a-z]{2,3})?")) |
| return true; |
| if (optionalErrorMessage) |
| @@ -86,9 +77,10 @@ bool PaymentsValidators::isValidLanguageCodeFormat( |
| return false; |
| } |
| -bool PaymentsValidators::isValidScriptCodeFormat(const String& code, |
| - String* optionalErrorMessage) { |
| - if (ScriptRegexp("^([A-Z][a-z]{3})?$", TextCaseSensitive).match(code) == 0) |
| +bool PaymentsValidators::isValidScriptCodeFormat( |
| + const std::string& code, |
| + std::string* optionalErrorMessage) { |
| + if (RE2::FullMatch(code, "([A-Z][a-z]{3})?")) |
| return true; |
| if (optionalErrorMessage) |
| @@ -101,8 +93,8 @@ bool PaymentsValidators::isValidScriptCodeFormat(const String& code, |
| } |
| bool PaymentsValidators::isValidShippingAddress( |
| - const mojom::blink::PaymentAddressPtr& address, |
| - String* optionalErrorMessage) { |
| + const blink::mojom::PaymentAddressPtr& address, |
| + std::string* optionalErrorMessage) { |
| if (!isValidCountryCodeFormat(address->country, optionalErrorMessage)) |
| return false; |
| @@ -112,7 +104,7 @@ bool PaymentsValidators::isValidShippingAddress( |
| if (!isValidScriptCodeFormat(address->script_code, optionalErrorMessage)) |
| return false; |
| - if (address->language_code.isEmpty() && !address->script_code.isEmpty()) { |
| + if (address->language_code.empty() && !address->script_code.empty()) { |
| if (optionalErrorMessage) |
| *optionalErrorMessage = |
| "If language code is empty, then script code should also be empty"; |
| @@ -123,9 +115,10 @@ bool PaymentsValidators::isValidShippingAddress( |
| return true; |
| } |
| -bool PaymentsValidators::isValidErrorMsgFormat(const String& error, |
| - String* optionalErrorMessage) { |
| - if (error.length() <= maxiumStringLength) |
| +bool PaymentsValidators::isValidErrorMsgFormat( |
| + const std::string& error, |
| + std::string* optionalErrorMessage) { |
| + if (error.length() <= maximumStringLength) |
| return true; |
| if (optionalErrorMessage) |
| @@ -135,4 +128,4 @@ bool PaymentsValidators::isValidErrorMsgFormat(const String& error, |
| return false; |
| } |
| -} // namespace blink |
| +} // namespace payments |