Skip to content

Conversation

escopecz
Copy link
Member

@escopecz escopecz commented Feb 4, 2025

Q A
Bug fix? (use the a.b branch) [y]
New feature/enhancement? (use the a.x branch) [ ]
Deprecations? [ ]
BC breaks? (use the c.x branch) [ ]
Automated tests included? [y]
Related user documentation PR URL mautic/mautic-documentation#...
Related developer documentation PR URL mautic/developer-documentation#...
Issue(s) addressed /

Description:

This PR fixes this error:

Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Symfony\Bundle\FrameworkBundle\Controller\Controller::redirect(): Argument #1 ($url) must be of type string, null given, called inapp/bundles/PageBundle/Controller/PublicController.php on line 64" at vendor/symfony/framework-bundle/Controller/ControllerTrait.php line 104

It uncovered that Landing Pages with configured redirect can be saved in an inconsistent state without the URL to redirect to. This PR fixes this to redirect to the 404-not found page instead instead of throwing the 500 error. And for the new pages it adds a validation to stop users creating such landing pages.

Plus:

  1. It simplifies the JS by using Mautic's system to show/hide fields based on another field value.
  2. It simplifies the code as it removes the unused constructor and config param that should have been removed in https://github.com/acquia/mc-cs/pull/553
  3. If an invalid URL was added to the redirect URL field, it prepended http:// to it and made it a valid URL. This behavior was removed and instead the validation message will be shown.

Steps to test this PR:

  1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs here)
  2. Create a new landing page
  3. Set the Redirect and do not set the redirect URL (it will not allow you to save such state with this PR)
  4. Unpublish the page
  5. Save
  6. Test the page in an incognito browser window. Even if you have a page with the redirect but not redirect URL either from before this fix was applied or via direct database manipulation, it will not error out but show the 404 page instead.

Other areas of Mautic that may be affected by the change:

  1. Just landing page form and API

List deprecations along with the new alternative:

  1. None

List of areas covered by the unit and/or functional tests:

  1. The tests are covering the existing pages in this inconsistent state that they will redirect to the 404 page
  2. And that the proper validation message will be shown for empty and invalid URL values.
  3. It also tests that the page will be saved with the valid URL.

Maut 12024 - Fixing invalid Page redirects
@escopecz escopecz added bug Issues or PR's relating to bugs code-review-needed PR's that require a code review before merging landing-pages Anything related to landing pages unforking Used for PRs in the Acquia's unforking initiative labels Feb 4, 2025
@escopecz escopecz added the ready-to-test PR's that are ready to test label Feb 4, 2025
@escopecz escopecz requested review from a team, pagupt and dadarya0 and removed request for a team and pagupt February 4, 2025 10:55
Copy link

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Project coverage is 64.54%. Comparing base (274dad0) to head (af1b26b).
Report is 4 commits behind head on 6.x.

Files with missing lines Patch % Lines
...bundles/PageBundle/Controller/PublicController.php 80.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                6.x   #14551      +/-   ##
============================================
+ Coverage     64.47%   64.54%   +0.06%     
- Complexity    34613    34614       +1     
============================================
  Files          2271     2271              
  Lines        103439   103442       +3     
============================================
+ Hits          66692    66766      +74     
+ Misses        36747    36676      -71     
Files with missing lines Coverage Δ
app/bundles/PageBundle/Entity/Page.php 91.59% <100.00%> (+7.14%) ⬆️
app/bundles/PageBundle/Form/Type/PageType.php 96.05% <ø> (+3.94%) ⬆️
.../bundles/PageBundle/Form/Type/RedirectListType.php 100.00% <ø> (ø)
...bundles/PageBundle/Controller/PublicController.php 71.36% <80.00%> (+1.10%) ⬆️

... and 1 file with indirect coverage changes

@escopecz escopecz added pending-test-confirmation PR's that require one test before they can be merged code-review-passed PRs which have passed code review and removed ready-to-test PR's that are ready to test code-review-needed PR's that require a code review before merging labels Feb 4, 2025
@escopecz escopecz requested review from a team, rohitpavaskar and aarohiprasad and removed request for a team and aarohiprasad February 7, 2025 16:21
@imaabasiee
Copy link

imaabasiee commented Feb 19, 2025

@escopecz I'm confused on how to go about testing this pr. On step 3, you said "Set the Redirect and do not set the redirect URL (it will not allow you to save such state with this PR)" so do I leave the redirect type field as no redirect? since I can't save the landing page without setting the redirect url if the redirect is set.

Copy link
Member

@kuzmany kuzmany left a comment

Choose a reason for hiding this comment

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

Code looks good.
I did basic tests, works.

Copy link
Contributor

@rohitpavaskar rohitpavaskar left a comment

Choose a reason for hiding this comment

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

Verified that this issue is reproducible on old branches and after applying this PR issue is resolved and validation message showing URL is required.
Thanks @escopecz!

@rohitpavaskar rohitpavaskar removed the pending-test-confirmation PR's that require one test before they can be merged label Feb 20, 2025
@rohitpavaskar rohitpavaskar added the user-testing-passed PRs which have been successfully tested by the required number of people. label Feb 20, 2025
@escopecz
Copy link
Member Author

@imaabasiee thanks for testing! This PR is adding a validation so this invalid state couldn't happen for new entities. But before this change was applied you could do that. So you'd have to replicate it on some other PR. I'm merging this as it has 2 approvals. Thanks everyone!

@escopecz escopecz added the ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged label Feb 26, 2025
@escopecz escopecz added this to the 6.0.0-beta milestone Feb 26, 2025
@escopecz escopecz merged commit 6e04391 into mautic:6.x Feb 26, 2025
17 checks passed
@RCheesley RCheesley modified the milestones: 6.0.0-beta, 6.0.0-beta2 Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs code-review-passed PRs which have passed code review landing-pages Anything related to landing pages ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged unforking Used for PRs in the Acquia's unforking initiative user-testing-passed PRs which have been successfully tested by the required number of people.
Projects
Status: 🥳 Done
Development

Successfully merging this pull request may close these issues.

6 participants