Skip to content
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

dev/core#2769 use php email validation not hacked & bad quickform function #21169

Merged
merged 1 commit into from
Aug 24, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

dev/core#2769 use php email validation not hacked qf

Before

Cannot save email name.-o-.i.10@example.com through back office contact edit screen (& others based on where this rule is in place)

After

It saves, but an obviously wrong email doesn't

Technical Details

Per https://lab.civicrm.org/dev/core/-/issues/2769 we have had problems over the years with
quickform's email validation and we now have a hacked version that is
problematic from a maintenance pov & also doesn't work
with the string I have just encountered: name.-o-.i.10@example.com
(which I am told is valid and which passes the php filter).

We already have an email rule which calls a php native function
which is better maintained than our layers of hacks. This
PR registers our email rule - which overrides the quickform
one. If we merge this we can revert quickform back to
unhacked which will improve debugging
and maintenance (although it's actually bypassed
now with this change)

Comments

@civibot
Copy link

civibot bot commented Aug 17, 2021

(Standard links)

@civibot civibot bot added the master label Aug 17, 2021
@eileenmcnaughton eileenmcnaughton changed the title dev/core#2769 use php email validation not hacked qf dev/core#2769 use php email validation not hacked & bad quickform function Aug 18, 2021
@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 that was a good call you made about requiring testing of the email address - I added the original one to the test & it does fail (this will) - I think the answer is to make our Utils_Rule function handle it (whatever it takes) - since it will be much easy to maintain a tested CRM function going forwards than a hacked QF fuction

@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 you might like to re-check this as I've made changes - I've copied over the idn_to_ascii from the hack to our core code & modified it so that it works with both variants

I've also carved out an exception for 'test@localhost' for sites in developer mode. Since @aydun raised it I thought we might as well handle it

@seamuslee001 seamuslee001 added merge ready PR will be merged after a few days if there are no objections and removed merge on pass labels Aug 20, 2021
@seamuslee001
Copy link
Contributor

This seems to make sense to me changed to merge ready in case anyone else wants to chime in

@mlutfy
Copy link
Member

mlutfy commented Aug 23, 2021

Looks good to me as well.

foreach ($parts as &$part) {
// if the function returns FALSE then let filter_var have at it.
$part = self::idnToAsci($part) ?: $part;
if ($part === 'localhost' && Civi::settings()->get('environment') === 'Development') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to check for Civi::settings()->get('environment') === 'Development'? Buildkit doesn't set this, the PR test runs and test sites don't set it, I never set it, and the original purpose of that setting I think had to do with stopping cron jobs from accidentally sending things out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demeritcowboy dunno - I can remove if people think I should - anyone else have an opinion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the unicorns have it - the environment check is gone

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* Test that 'test@localhost' works in dev environments.
*/
public function testDevelopmentEmail(): void {
Civi::settings()->set('environment', 'Development');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton This line needs to go too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire yeah - I just removed that test as it is meaningless now

Per https://lab.civicrm.org/dev/core/-/issues/2769 we have had problems over the years with
quickform's email validation and we now have a hacked version that is
problematic from a maintenance pov & also doesn't work
with the string I have just encountered: name.-o-.i.10@example.com
(which I am told is valid and which passes the php filter).

We already have an email rule which calls a php native function
which is better maintained than our layers of hacks. This
PR registers our email rule - which overrides the quickform
one. If we merge this we can revert quickform back to
unhacked which will improve debugging
and maintenance (although it's actually bypassed
now with this change)
@eileenmcnaughton
Copy link
Contributor Author

I think we can merge this now?

@seamuslee001
Copy link
Contributor

Looks good to me

@seamuslee001 seamuslee001 merged commit 0239643 into civicrm:master Aug 24, 2021
@seamuslee001 seamuslee001 deleted the email branch August 24, 2021 22:20
@eileenmcnaughton
Copy link
Contributor Author

thanks all - I think having less hacked spaces will be better for our brains

@seamuslee001 did you see the related package prs to remove the QF hack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-test master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants