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

Fix custom Home URL parsing #13031

Merged

Conversation

davialexandre
Copy link
Member

@davialexandre davialexandre commented Oct 29, 2018

Overview

The code used to parse a custom Home URL in the CRM_Core_BAO_Navigation::createNavigation() would throw an E_NOTICE if the URL did not contain a query string.

Also, URL fragments would be removed from the parsed URL.

Before

Custom Home URLs without a query string would result in an E_NOTICE.

Fragments in a custom URL would be removed.

After

No E_NOTICE is thrown when parsing a custom Home URL without a query string.

Fragments are not removed from the custom URL.

Technical Details

The reason for the E_NOTICE was the usage of explode() to extract the parts of the URL and then using list() to assign the parts to variables. When the query string is not present, explode() will return an array with one single element and the assignment will fail. This was fixed by using the parse_url() function to query for the relevant parts of the URL.

There was also a problem where the previous code would end up removing fragments from the URL. This has also been fixed using parse_url() to get the fragment.

Finally, some minor cleanup was done in 2e42cb1. The $contactId param and the $config variable were not used anywhere inside the method, so I removed them.

Comments

Since this a quite simple fix, I thought it would be ok to not create a Gitlab ticket first. If the ticket is necessary, please let me know and I'll create it.

The list assignment will result in an E_NOTICE when the Home URL does
not contain a query string, because the array returned by the explode()
call will contain only one item.
@civibot
Copy link

civibot bot commented Oct 29, 2018

(Standard links)

@civibot civibot bot added the master label Oct 29, 2018
@colemanw
Copy link
Member

I just fixed a very similar problem in a different place. See #12702 #12876.
IMO the block of code beginning with if (!empty($url)) { needs to be extracted into a function so it can be reused here as you are basically duplicating that code here.

@davialexandre
Copy link
Member Author

@colemanw I've extracted the duplicated code as suggested. I don't really like the name of the new extracted method, but I couldn't come up with anything better than that. Part of the reason, maybe, is because I don't fully understand why this processing is necessary in the first place. At first, I thought it was some kind of validation, but since I was not so sure I decided to go with the more generic processUrl(). If you have any suggestions for a better name I'd be happy to update it.

@colemanw
Copy link
Member

colemanw commented Oct 30, 2018

Looks good.
What it's doing is turning relative urls like "civicrm/dashboard" into fully-formed urls like "https://example.com/wp-admin?q=civicrm/dashboard" (unless the url is fully formed already).

@davialexandre davialexandre force-pushed the fix-custom-home-url-parsing branch from 2c6ba7c to 0f1c746 Compare October 30, 2018 17:37
@davialexandre
Copy link
Member Author

changed the method name from processUrl() to makeFullyFormedUrl()

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@eileenmcnaughton
Copy link
Contributor

Test Result (1 failure / +1)
CRM_Member_Form_MembershipTest.testFinancialEntiriesOnCancelledContribution

seems unrelated - will retry

@eileenmcnaughton
Copy link
Contributor

test this please

@eileenmcnaughton eileenmcnaughton merged commit 9983edf into civicrm:master Oct 31, 2018
davialexandre added a commit to compucorp/civicrm-core that referenced this pull request Nov 1, 2018
Included in CiviCRM 5.8.0
Core PR: civicrm#13031
davialexandre added a commit to compucorp/civihr that referenced this pull request Nov 1, 2018
The only reason we needed the overridden file was to fix an
error in CiviCRM Core. Since this has been now fixed in core,
we don't need to file anymore.

References: civicrm/civicrm-core#13031
compucorp/civicrm-core#28
davialexandre added a commit to compucorp/civicrm-core that referenced this pull request Nov 1, 2018
Included in CiviCRM 5.8.0
Core PR: civicrm#13031
davialexandre added a commit to compucorp/civihr that referenced this pull request Nov 6, 2018
The only reason we needed the overridden file was to fix an
error in CiviCRM Core. Since this has been now fixed in core,
we don't need to file anymore.

References: civicrm/civicrm-core#13031
compucorp/civicrm-core#28
davialexandre added a commit to compucorp/civicrm-core that referenced this pull request Nov 9, 2018
Included in CiviCRM 5.8.0
Core PR: civicrm#13031
@davialexandre davialexandre deleted the fix-custom-home-url-parsing branch December 18, 2018 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants