-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loosen the validation on setting country in payment propertyBag to handle buggy code #24903
Conversation
(Standard links)
|
@mattwire is this a good idea? It affects |
The good thing is the unit test fail flags where to add a new unit test :-) |
I guess the flip side to my thoughts about it making |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(SCRAP THIS)
I think logging this stuff is useful to search out places where the data is being incorrectly supplied, however this passes the problem on down the line - it means we accept whatever junk passed in as billingCountry, so we will output the same junk too, which likely leads to multiple implementations of fixes for this problem by the consumers of the propertybag.
Would it be too much to, as Eileen suggests do
if is_string and isISO3166ok: accept
elseif !empty && (is_int || preg_match('/^\d+$/')) && idMatchesCountryId: lookup and map to the ISO3166 code. Log warning
elseif !empty && is_string && matches country name: lookup and map to the ISO3166 code. Log warning.
else store NULL (as what we have cannot be valid) and log warning
EDIT: I've put my preferred aproach at #24927
@@ -647,10 +647,12 @@ public function getBillingCountry($label = 'default') { | |||
*/ | |||
public function setBillingCountry($input, $label = 'default') { | |||
if (!is_string($input) || strlen($input) !== 2) { | |||
throw new \InvalidArgumentException("setBillingCountry expects ISO 3166-1 alpha-2 country code."); | |||
\Civi::log()->error('setBillingCountry expects ISO 3166-1 alpha-2 country code. Attempted to use "' . $input . '"'); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
} | ||
if (!CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Address', 'country_id', $input)) { | ||
throw new \InvalidArgumentException("setBillingCountry expects ISO 3166-1 alpha-2 country code."); | ||
\Civi::log()->error('setBillingCountry expects ISO 3166-1 alpha-2 country code. "' . $input . '" not found in database.'); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Closing in favour of #24927 |
Overview
See https://lab.civicrm.org/dev/core/-/issues/3918
Before
Crash if bad country data passed in.
After
Logged in bad country data passed in.
Technical Details
Comments
Alternative to #24894