Mwalker has uploaded a new change for review.
https://gerrit.wikimedia.org/r/54613
Change subject: Check moar fields for CC numbers
......................................................................
Check moar fields for CC numbers
Because people add them here too
Change-Id: I6efbda38405123897782bbc07669b5de08b95f01
---
M gateway_common/DataValidator.php
1 file changed, 29 insertions(+), 1 deletion(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/13/54613/1
diff --git a/gateway_common/DataValidator.php b/gateway_common/DataValidator.php
index 1301028..46f1240 100644
--- a/gateway_common/DataValidator.php
+++ b/gateway_common/DataValidator.php
@@ -394,6 +394,10 @@
break;
case 'validate_name':
$check_type = 'calculated';
+ break;
+ case 'validate_address':
+ $check_type = 'calculated';
+ break;
}
$instructions[$check_type][$field] =
$function_name;
}
@@ -526,6 +530,9 @@
return 'validate_name';
case 'currency_code':
return 'validate_currency_code';
+ case 'city':
+ case 'street':
+ return 'validate_address';
}
if ( in_array( $field, self::getNumericFields() ) ){
@@ -550,6 +557,13 @@
protected static function validate_email( $value ){
// is email address valid?
$isEmail = Sanitizer::validateEmail( $value );
+ if ( $isEmail ) {
+ // Because people put CC numbers in this field too
+ $tmp = preg_replace( '/[^0-9]/', '', $value );
+ if ( is_numeric( $tmp ) ) {
+ $isEmail = !DataValidator::luhn_check( $value );
+ }
+ }
return $isEmail;
}
@@ -765,7 +779,7 @@
* on the name to make sure it's not actually a potentially valid CC
number.
*
* @param string $value Ze name!
- * @returns boolean True if the name is not suspiciously like a CC
number
+ * @return boolean True if the name is not suspiciously like a CC number
*/
public static function validate_name( $value ) {
$value = preg_replace( '/[^0-9]/', '', $value );
@@ -777,6 +791,20 @@
}
/**
+ * Gets rid of numbers that pass luhn in address fields - @see
validate_name
+ * @param $value
+ * @return bool True if suspiciously like a CC number
+ */
+ public static function validate_address( $value ) {
+ $value = preg_replace( '/[^0-9]/', '', $value );
+ if ( is_numeric( $value ) ) {
+ return !DataValidator::luhn_check( $value );
+ } else {
+ return true;
+ }
+ }
+
+ /**
* Performs a Luhn algorithm check on a string.
*
* @param $str
--
To view, visit https://gerrit.wikimedia.org/r/54613
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6efbda38405123897782bbc07669b5de08b95f01
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits