Skip to content

Fix toolbar load when GET params are present in "_wdt" route #32437

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

Merged
merged 1 commit into from
Sep 27, 2019

Conversation

Molkobain
Copy link
Contributor

@Molkobain Molkobain commented Jul 8, 2019

When using a custom router that inject GET parameters, eg:

# services.yaml
parameters:
    # Replace default url generator service
    router.options.generator_base_class: Combodo\iTop\Portal\Routing\UrlGenerator

The path generated by the toolbar JS is HTML entity encoded which breaks the JS call (& becomes &).

Q A
Branch? 4.4 for features / 3.4, 4.2 or 4.3 for bug fixes
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #...
License MIT
Doc PR symfony/symfony-docs#...

When using a custom router that inject GET parameters, eg:

```
# services.yaml
parameters:
    # Replace default url generator service
    router.options.generator_base_class: Combodo\iTop\Portal\Routing\UrlGenerator
```

The path generated by the toolbar JS is HTML entity encoded which breaks the JS call (`&` becomes `&`).
@derrabus
Copy link
Member

derrabus commented Jul 8, 2019

Can you provide a minimal application that reproduces the problem?

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jul 10, 2019
@fabpot
Copy link
Member

fabpot commented Jul 27, 2019

@Molkobain Can you tell us more about this issue?

@Molkobain
Copy link
Contributor Author

Molkobain commented Jul 27, 2019

Hello guys,

What do you means by a minimal app?

About the issue, we extended the base UrlGenerator to propagate some parameters to all generated URLs as you will see on the code snippet below. It works fine in the application, URLs are generated as expected.

<?php
namespace Combodo\iTop\Portal\Routing;

use utils;
use Symfony\Component\Routing\Generator\UrlGenerator as BaseUrlGenerator;

class UrlGenerator extends BaseUrlGenerator
{
	protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array())
	{
		$parameters = $this->getExtraParams($parameters);

		return parent::doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, $requiredSchemes);
	}

	private function getExtraParams($aParameters)
	{
		$sExecModule = utils::ReadParam('exec_module', '', false, 'string');
		$sExecPage = utils::ReadParam('exec_page', '', false, 'string');
		if ($sExecModule !== '' && $sExecPage !== '')
		{
			$aParameters['exec_module'] = $sExecModule;
			$aParameters['exec_page'] = $sExecPage;
		}

		// Optional parameters
		$sPortalId = utils::ReadParam('portal_id', '', false, 'string');
		if ($sPortalId !== '')
		{
			$aParameters['portal_id'] = $sPortalId;
		}
		$sEnvSwitch = utils::ReadParam('env_switch', '', false, 'string');
		if ($sEnvSwitch !== '')
		{
			$aParameters['env_switch'] = $sEnvSwitch;
		}
		$sDebug = utils::ReadParam('debug', '', false, 'string');
		if ($sDebug !== '')
		{
			$aParameters['debug'] = $sDebug;
		}

		return $aParameters;
	}
}

The problem comes with the webprofiler in the webpage, when it tries to connect with the backend through XHR, the URL it calls is HTML entity encoded (check the "&"):

http://localhost/pages/exec.php/_wdt/5f220b?exec_module=itop-portal-base&amp;exec_page=index.php&amp;portal_id=itop-portal

The backend then cannot decode the parameters and returns an error.

Edit: Pressed Alt+Enter by mistake. I'm completing the comment and poking you when its complete. Sorry

@Molkobain
Copy link
Contributor Author

Edit complete @fabpot @derrabus

@fabpot
Copy link
Member

fabpot commented Sep 27, 2019

Thank you @Molkobain.

fabpot added a commit that referenced this pull request Sep 27, 2019
…te (Molkobain)

This PR was merged into the 3.4 branch.

Discussion
----------

Fix toolbar load when GET params are present in "_wdt" route

When using a custom router that inject GET parameters, eg:

```
# services.yaml
parameters:
    # Replace default url generator service
    router.options.generator_base_class: Combodo\iTop\Portal\Routing\UrlGenerator
```

The path generated by the toolbar JS is HTML entity encoded which breaks the JS call (`&` becomes `&amp;`).

| Q             | A
| ------------- | ---
| Branch?       | 4.4 for features / 3.4, 4.2 or 4.3 for bug fixes <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->

Commits
-------

5309e64 Fix toolbar load when GET params are present in "_wdt" route
@fabpot fabpot merged commit 5309e64 into symfony:3.4 Sep 27, 2019
This was referenced Oct 7, 2019
@Molkobain Molkobain deleted the patch-1 branch February 13, 2023 12:52
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.

5 participants