Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle] Fixed issue when a parameter contains a '%' #30930

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
May 11, 2019

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Apr 6, 2019

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #31431
License MIT
Doc PR

On my computer:

dump(get_cfg_var('xdebug.file_link_format'));
"subl://%f:%l"

When I ran bin/console debug:config framework I got this exception:


In ParameterBag.php line 100:

  [Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
  The parameter "templating.helper.code.file_link_format" has a
dependency on a non-existent parameter "f:".

Exception trace:
 () at
/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:100
...

This issue was introduced here / cc @ro0NL

This PR does not really fix the issue: I'm able to debug the config, The
the debug:container --env-vars does not work anymore. How could we fix
both issue? cc @nicolas-grekas

@lyrixx lyrixx changed the title [WIP] [FrameworkBundle] Fixed issue when a parameter container a '%' [WIP] [FrameworkBundle] Fixed issue when a parameter contains a '%' Apr 6, 2019
@nicolas-grekas nicolas-grekas added this to the next milestone Apr 7, 2019
@nicolas-grekas
Copy link
Member

Status: needs work

@ro0NL
Copy link
Contributor

ro0NL commented Apr 8, 2019

Hm, looking at the dumped XML.. i see:

<parameter key="templating.helper.code.file_link_format">subl://%f:%l</parameter>
<parameter key="debug.file_link_format">subl://%f:%l</parameter>

if i escape % manually, it's solved.

@ro0NL
Copy link
Contributor

ro0NL commented Apr 8, 2019

if ($this->container->isCompiled()) {
$data = $this->escape($data);
}

shouldnt we always escape at the output level? 🤔

@lyrixx
Copy link
Member Author

lyrixx commented Apr 8, 2019

@ro0NL Unfortunately, the dumped container does not really work. It contains escaped values, and un-escaped values. This is really not simple. IMHO, the simplest (and a bit dirty) solution is to continue in the way I started this PR :/ We should not try to recompile a compiled container, instead we should grep the dumped container, and extract all env var. This PR is almost done, but I'm not able to get the real default value. But I did not get enough time to work on it

@ro0NL
Copy link
Contributor

ro0NL commented Apr 8, 2019

We should not try to recompile a compiled container

but the xml is not compiled yet, at most it's an optimized dump from a compiled source. But IIUC we should be able to compile it again (and get the same result).

from ContainerDebugCommand::getContainerBuilder() is at least weird we compile the container conditionally.

@ro0NL
Copy link
Contributor

ro0NL commented Apr 8, 2019

i mean if we cant load a dumped XML and compile it as such.. that's another bug no?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 8, 2019

I don't think it's a bug, there are tests making it pretty clear it's on purpose: if you dump a compiled container, you should not compile it again. That's the root of the issue here. If you dumped a non-compiled container, then the dumped file should keep references to parameters - thus encode %.
We should build with these constraints in mind - not against them.

@ro0NL
Copy link
Contributor

ro0NL commented Apr 8, 2019

if you dump a compiled container, you should not compile it again

This leaves the container(builder) in PHP uncompiled though (i.e. isCompiled() = false). It feels like a weird discrepancy, where XmlFileLoader should mark the container compiled if it loads a compiled container.

@nicolas-grekas
Copy link
Member

XmlFileLoader should mark the container compiled if it loads a compiled container.

I agree, would you mind having a look?

@ro0NL
Copy link
Contributor

ro0NL commented Apr 8, 2019

Hm this is hard :) in XML we could consider differentiating based on e.g. compiled="true" .. but what about YAML? This also implies a new feature, as such i think the current dumps are intended to be uncompiled.

If so, we need to find another way to track getEnvCounters() which is perhaps easier :/ (edit: ah i see the current approach is updated already).

@nicolas-grekas
Copy link
Member

preg_match_all() to the rescue, that's way enough to me for the targeted feature.

@nicolas-grekas
Copy link
Member

@nicolas-grekas
Copy link
Member

@ro0NL I would appreciate your thoughts here too, since this builds on a PR of yours :)

@lyrixx
Copy link
Member Author

lyrixx commented May 9, 2019

OH, I was working on it ATM !

@lyrixx
Copy link
Member Author

lyrixx commented May 9, 2019

@nicolas-grekas your patch did not work, it did not use the real default value. See my patch, I pushed force too (after you)

@lyrixx
Copy link
Member Author

lyrixx commented May 9, 2019

Looks like everything is OK:

>…/dev/labs/symfony/website-skeleton(4.3-percent *) git di
diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml
index 9521fad..fc592a8 100644
--- a/config/packages/doctrine.yaml
+++ b/config/packages/doctrine.yaml
@@ -3,7 +3,7 @@ parameters:
     # This allows you to run cache:warmup even if your
     # environment variables are not available yet.
     # You should not need to change this value.
-    env(DATABASE_URL): ''
+    env(DATABASE_URL): 'THE DEFAULT VALUEEEE'
 
 doctrine:
     dbal:
>…/dev/labs/symfony/website-skeleton(4.3-percent *) bin/console  debug:cont --env-vars -v   

Symfony Container Environment Variables
=======================================

 ------------------- ------------------------ ------------------------------------------------------ 
  Name                Default value            Real value                                            
 ------------------- ------------------------ ------------------------------------------------------ 
  APP_SECRET          n/a                      "48a7a9817123a382c84981b98d8748f1"                    
  DATABASE_URL        "THE DEFAULT VALUEEEE"   "mysql://db_user:db_password@127.0.0.1:3306/db_name"  
  MAILER_URL          n/a                      "null://localhost"                                    
  VAR_DUMPER_SERVER   "127.0.0.1:9912"         n/a                                                   
 ------------------- ------------------------ ------------------------------------------------------ 

 // Note real values might be different between web and CLI.                                                            

>…/dev/labs/symfony/website-skeleton(4.3-percent *) DATABASE_URL=HELLO bin/console  debug:cont --env-vars -v

Symfony Container Environment Variables
=======================================

 ------------------- ------------------------ ------------------------------------ 
  Name                Default value            Real value                          
 ------------------- ------------------------ ------------------------------------ 
  APP_SECRET          n/a                      "48a7a9817123a382c84981b98d8748f1"  
  DATABASE_URL        "THE DEFAULT VALUEEEE"   "HELLO"                             
  MAILER_URL          n/a                      "null://localhost"                  
  VAR_DUMPER_SERVER   "127.0.0.1:9912"         n/a                                 
 ------------------- ------------------------ ------------------------------------ 

 // Note real values might be different between web and CLI.                                                            

@ro0NL
Copy link
Contributor

ro0NL commented May 9, 2019

You have requested a non-existent parameter "debug.container.dump"

seems now the other case is failing :) not sure if both cases are tested actually. in general the regex approach works for me 👍

@lyrixx
Copy link
Member Author

lyrixx commented May 9, 2019

seems now the other case is failing :) not sure if both cases are tested actually. in general the regex approach works for me 👍

How did you get this error? I saw this is thrown is the CI but did you get it locally?

@ro0NL
Copy link
Contributor

ro0NL commented May 9, 2019

also looking at CI :)

@nicolas-grekas nicolas-grekas changed the title [WIP] [FrameworkBundle] Fixed issue when a parameter contains a '%' [FrameworkBundle] Fixed issue when a parameter contains a '%' May 10, 2019
@lyrixx
Copy link
Member Author

lyrixx commented May 10, 2019

I'm fixing some issues, but I don't get why your regex is better. With

        preg_match_all('{([%"])env\(((?:\w++:)*+\w++)\)\1}', $file, $envVars);
        dump($envVars);die;

I got:

array:3 [
  0 => array:8 [
    0 => ""env(DATABASE_URL)""
    1 => "%env(APP_SECRET)%"
    2 => ""env(VAR_DUMPER_SERVER)""
    3 => "%env(APP_SECRET)%"
    4 => "%env(resolve:DATABASE_URL)%"
    5 => "%env(MAILER_URL)%"
    6 => "%env(VAR_DUMPER_SERVER)%"
    7 => "%env(VAR_DUMPER_SERVER)%"
  ]
  1 => array:8 [
    0 => """
    1 => "%"
    2 => """
    3 => "%"
    4 => "%"
    5 => "%"
    6 => "%"
    7 => "%"
  ]
  2 => array:8 [
    0 => "DATABASE_URL"
    1 => "APP_SECRET"
    2 => "VAR_DUMPER_SERVER"
    3 => "APP_SECRET"
    4 => "resolve:DATABASE_URL"
    5 => "MAILER_URL"
    6 => "VAR_DUMPER_SERVER"
    7 => "VAR_DUMPER_SERVER"
  ]
]

Where I got before:

array:2 [
  0 => array:6 [
    0 => "%env(APP_SECRET)%"
    1 => "%env(APP_SECRET)%"
    2 => "%env(resolve:DATABASE_URL)%"
    3 => "%env(MAILER_URL)%"
    4 => "%env(VAR_DUMPER_SERVER)%"
    5 => "%env(VAR_DUMPER_SERVER)%"
  ]
  1 => array:6 [
    0 => "APP_SECRET"
    1 => "APP_SECRET"
    2 => "resolve:DATABASE_URL"
    3 => "MAILER_URL"
    4 => "VAR_DUMPER_SERVER"
    5 => "VAR_DUMPER_SERVER"
  ]
]

Could you give me some example of what I need to match

@ro0NL
Copy link
Contributor

ro0NL commented May 10, 2019

i thought it was nessecary to include default envs, in order to obtain the default values. But now you obtain them directly from the parameter bag, so it's not needed anymore.

On my computer:
```
dump(get_cfg_var('xdebug.file_link_format'));
"subl://%f:%l"
```

When I ran `bin/console debug:config framework` I got this exception:

```

In ParameterBag.php line 100:

  [Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
  The parameter "templating.helper.code.file_link_format" has a
dependency on a non-existent parameter "f:".

Exception trace:
 () at
/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:100
...
```

This issue was introduced
[here](https://github.com/symfony/symfony/pull/27684/files#diff-b3847149480405e1de881530b4c75ab5L212)
@lyrixx
Copy link
Member Author

lyrixx commented May 10, 2019

Here we go ...
I had to move a test because trailing spaces are so boring ...

@nicolas-grekas
Copy link
Member

I don't get why your regex is better

because mine is more specific: .* vs (?:\w++:)*+\w++, which matches how EnvParameterBar works.

@lyrixx
Copy link
Member Author

lyrixx commented May 10, 2019

It should be OK. Tests pass locally and I guess it's the expected behavior on a regular app :)
@ro0NL Is it OK for you?

@nicolas-grekas
Copy link
Member

Thank you @lyrixx.

@nicolas-grekas nicolas-grekas merged commit 7bcd714 into symfony:4.3 May 11, 2019
nicolas-grekas added a commit that referenced this pull request May 11, 2019
…'%' (lyrixx)

This PR was merged into the 4.3 branch.

Discussion
----------

[FrameworkBundle] Fixed issue when a parameter contains a '%'

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31431
| License       | MIT
| Doc PR        |

---

On my computer:
```
dump(get_cfg_var('xdebug.file_link_format'));
"subl://%f:%l"
```

When I ran `bin/console debug:config framework` I got this exception:

```

In ParameterBag.php line 100:

  [Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
  The parameter "templating.helper.code.file_link_format" has a
dependency on a non-existent parameter "f:".

Exception trace:
 () at
/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:100
...
```

This issue was introduced [here](https://github.com/symfony/symfony/pull/27684/files#diff-b3847149480405e1de881530b4c75ab5L212) / cc @ro0NL

This PR does not really fix the issue: I'm able to debug the config, The
the `debug:container --env-vars` does not work anymore. How could we fix
both issue? cc @nicolas-grekas

Commits
-------

7bcd714 [FrameworkBundle] Fixed issue when a parameter container a '%'
@lyrixx lyrixx deleted the fix-config branch May 11, 2019 18:00
@fabpot fabpot mentioned this pull request May 22, 2019
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.