Skip to content

Some branch #2

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 5 commits into from
Apr 6, 2021
Merged

Some branch #2

merged 5 commits into from
Apr 6, 2021

Conversation

mkrogulec
Copy link

Q A
Branch? master for features / 3.4, 4.4, 5.0 or 5.1 for bug fixes
Bug fix? yes/no
New feature? yes/no
Deprecations? yes/no
Tickets Fix #...
License MIT
Doc PR symfony/symfony-docs#...

@mkrogulec mkrogulec requested a review from chalasr as a code owner April 6, 2021 17:09
@chalasr chalasr merged commit 062e7ce into chalasr:5.x Apr 6, 2021
chalasr pushed a commit that referenced this pull request May 7, 2021
…e (Plopix)

This PR was merged into the 4.4 branch.

Discussion
----------

RequestMatcher issue when `_controller` is a closure

| Q             | A
| ------------- | ---
| Branch?       |  4.4
| Bug fix?      |  yes
| New feature?  | no
| Deprecations? |  no
| License       | MIT

## Description

If the `matches` method of `RequestMatcher` is used on an attribute which is a closure it crashes.

##  How did we get it

On a project that is using FOS HTTP Cache, we have this configuration

```yaml
fos_http_cache:
    cache_control:
        rules:
     -
                match:
                    attributes: { _controller: ^App\\Controller\\.*::.* }
                headers:
                    overwrite: true
                    cache_control: { public: true, private: false, must_revalidate: true, s_maxage: 3600 }
```

Everything works fine unless you are reaching a controller that is a closure.
You get a
```TypeError: preg_match(): Argument #2 ($subject) must be of type string, Closure given``` which is to me logical.

## Proposed solution

Just testing the type of attribute value and return false before crashing `preg_match`

This PR adds a quick unit test to enforce this.

Commits
-------

6649123 Fix issue with RequestMatcher when attribute is a closure
chalasr pushed a commit that referenced this pull request May 7, 2021
…h case insensitive (javiereguiluz)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[FrameworkBundle] Make debug:event-dispatcher search case insensitive

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

I was playing with the new features of `debug:event-dispatcher` and I thought that making the new search feature case insensitive could be better:

### Before

```
$ php bin/console debug:event-dispatcher mailer

 [WARNING] The event "mailer" does not have any registered listeners.
```

### After

```
$ php bin/console debug:event-dispatcher mailer

Registered Listeners of Event Dispatcher "debug.event_dispatcher" for "Symfony\Component\Mailer\Event\MessageEvent" Event
=========================================================================================================================

 ------- --------------------------------------------------------------------------- ----------
  Order   Callable                                                                    Priority
 ------- --------------------------------------------------------------------------- ----------
  #1      Symfony\Component\Mailer\EventListener\MessageListener::onMessage()         0
  #2      Symfony\Component\Mailer\EventListener\EnvelopeListener::onMessage()        -255
  #3      Symfony\Component\Mailer\EventListener\MessageLoggerListener::onMessage()   -255
 ------- --------------------------------------------------------------------------- ----------
```

Commits
-------

1e4c7d9 [FrameworkBundle] Make debug:event-dispatcher search case insensitive
chalasr pushed a commit that referenced this pull request Jan 5, 2022
DOMElement::setAttribute(): Passing null to parameter #2 ($value) of type string is deprecated

This happens when a tag value is `null` on PHP 8.1.
chalasr pushed a commit that referenced this pull request Jan 5, 2022
…tring (ruudk)

This PR was merged into the 4.4 branch.

Discussion
----------

[DependencyInjection] Cast tag attribute value to string

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  |no
| Deprecations? |no
| Tickets       |
| License       | MIT
| Doc PR        |

```
DOMElement::setAttribute(): Passing null to parameter #2 ($value) of type string is deprecated
```
This happens when a tag value is `null` on PHP 8.1.

Commits
-------

8fe5fce [DependencyInjection] Cast tag value to string
chalasr pushed a commit that referenced this pull request Jan 24, 2022
…tations (sormes)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Validator] Error using CssColor with doctrine annotations

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | none
| License       | MIT

When use doctrine annotations and set formats parameter throw and error

`array_merge(): Argument #2 must be of type array, null given`

`in vendor/symfony/validator/Constraints/CssColor.php (line 75) `

Commits
-------

bba6e15 [Validator] Error using CssColor with doctrine annotations
chalasr pushed a commit that referenced this pull request Feb 7, 2022
… resource (Seldaek)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[Process] Avoid calling fclose on an already closed resource

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

I got this in Composer while interrupting an install process with Ctrl-C.

```
PHP Fatal error:  Uncaught TypeError: fclose(): supplied resource is not a valid stream resource in /var/www/composer/vendor/symfony/process/Pipes/AbstractPipes.php:50
Stack trace:
#0 /var/www/composer/vendor/symfony/process/Pipes/AbstractPipes.php(50): fclose()
#1 /var/www/composer/vendor/symfony/process/Pipes/UnixPipes.php(50): Symfony\Component\Process\Pipes\AbstractPipes->close()
#2 [internal function]: Symfony\Component\Process\Pipes\UnixPipes->__destruct()
#3 {main}
  thrown in /var/www/composer/vendor/symfony/process/Pipes/AbstractPipes.php on line 50
```

I am assuming it's due to a process which was not closed properly, which is very likely given we run a bunch of them concurrently.. It's pretty hard to debug as it's also hard to reproduce, so I am not sure what to do except handle this case gracefully in the close/__destruct function and hope that at least lets it clean up processes without crashing this way.

Commits
-------

a9e43a7 [Process] Avoid calling fclose on an already closed resource
chalasr pushed a commit that referenced this pull request Mar 10, 2022
…usse)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] Handle requests with null body

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | /
| License       | MIT
| Doc PR        | /

since symfony#45527 passing null to the `body` parameters leads to an exception (which [breaks async-aws](https://github.com/async-aws/aws/blob/09723ddca29b8d1d522426f81dd422373de1785f/src/Core/src/AbstractApi.php#L157))

> Argument #2 ($body) must be of type Closure, null given, called in /home/runner/work/aws/aws/vendor/symfony/http-client/CurlHttpClient.php on line 221

In curl client: `null` is not a string and `self::readRequestBody` expects a closure.

https://github.com/symfony/symfony/blob/08fa74a16c84895575e305b2a7ee3a03e371f79b/src/Symfony/Component/HttpClient/CurlHttpClient.php#L214-L221

In NativeClient, `getBodyAsString` will fail to return `null` because of the `string` return type.

Before symfony#45527 null was converted to `""` thanks to the defaultOptions, but this is not the case anymore.

In many places, we check if the body is `!== ""` but rarely check if the body is null, this PR restores the original behaviors for the `body` parameters and converts nulls to `""`.

Commits
-------

39aec09 [HttpClient] Handle requests with null body
chalasr pushed a commit that referenced this pull request Apr 15, 2022
Because Security::LAST_USERNAME not always exist, it can trigger a "preg_match(): Argument #2 ($subject) must be of type string" if $username is null
chalasr added a commit that referenced this pull request Apr 15, 2022
…Security::LAST_USERNAME (David-Crty)

This PR was merged into the 5.4 branch.

Discussion
----------

[RateLimiter] Adding default empty string value on Security::LAST_USERNAME

Because `Security::LAST_USERNAME` not always exist, it can trigger a `preg_match(): Argument #2 ($subject) must be of type string` if $username is null

The error is critical when having `declare(strict_types=1)`, to avoid issue when people create their own LoginRateLimiter from the DefaultLoginRateLimiter we can juste set a default empty string.

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| License       | MIT

Commits
-------

0fdfcae [RateLimiter] Adding default empty value
chalasr pushed a commit that referenced this pull request Jul 4, 2022
In the cached file of my application I can see the following code fragment that have been generated by Symfony:
```php
if (( !((array_key_exists("render_preferred_choices", $context)) ? (_twig_default_filter((isset($context["render_preferred_choices"]) || array_key_exists("render_preferred_choices", $context) ? $context["render_preferred_choices"] : (function () { throw new RuntimeError('Variable "render_preferred_choices" does not exist.', 88, $this->source); })()), false)) : (false)) && Symfony\Bridge\Twig\Extension\twig_is_selected_choice($context["choice"], (isset($context["value"]) || array_key_exists("value", $context) ? $context["value"] : (function () { throw new RuntimeError('Variable "value" does not exist.', 88, $this->source); })())))) {
                    echo " selected=\"selected\"";
                }
```

The 2nd Arg passed when calling ``twig_is_selected_choice`` if the result of ``(isset($context["value"]) || array_key_exists("value", $context) ? $context["value"]``.

In that condition, if ``$context['value'] = null, we pass the null

Currently I got the following error:
```
Symfony\Bridge\Twig\Extension\twig_is_selected_choice(): Argument #2 ($selectedValue) must be of type array|string, null given, called in X:\workspace-novento\novento-vip-lounge\var\cache\admin_dev\twig\01\01615438ee40292438687b29025d08a9.php on line 534
```
chalasr pushed a commit that referenced this pull request Jul 4, 2022
…el057)

This PR was merged into the 6.0 branch.

Discussion
----------

Allow passing null in twig_is_selected_choice

| Q             | A
| ------------- | ---
| Branch?       | 6.0 and >
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| License       | MIT

In the cached file of my application, generated by Symfony I can see the following code fragment:
```php
if (( !((array_key_exists("render_preferred_choices", $context)) ? (_twig_default_filter((isset($context["render_preferred_choices"]) ||
array_key_exists("render_preferred_choices", $context) ? $context["render_preferred_choices"] : (function () { throw new
RuntimeError('Variable "render_preferred_choices" does not exist.', 88, $this->source); })()), false)) : (false)) && Symfony\Bridge
\Twig\Extension\twig_is_selected_choice($context["choice"], (isset($context["value"]) || array_key_exists("value", $context) ?
$context["value"] : (function () { throw new RuntimeError('Variable "value" does not exist.', 88, $this->source); })())))) {
                    echo " selected=\"selected\"";
                }
```

The 2nd Arg passed when calling ``twig_is_selected_choice`` is the result of ``(isset($context["value"]) || array_key_exists("value", $context) ? $context["value"]``. So in case ``$context['value'] = null``, we pass ``null`` as 2nd arg of ``twig_is_selected_choice``.

As a result in some case, when I submit form with empty (null) value, I got the following error:
```
Symfony\Bridge\Twig\Extension\twig_is_selected_choice(): Argument #2 ($selectedValue) must be of type array|string, null given, called in ...\var\cache\dev\twig\01\01615438ee40292438687b29025d08a9.php on line 534
```

Commits
-------

0186ecb Allow passing null in twig_is_selected_choice
chalasr pushed a commit that referenced this pull request Jul 22, 2022
…es (SerafimArts)

This PR was squashed before being merged into the 6.2 branch.

Discussion
----------

[VarDumper] Add `FFI\CData` and `FFI\CType` types

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Added support of FFI:
```php
$ffi = \FFI::cdef(<<<'CPP'
    typedef struct { int x; int y; } Point;
    typedef struct Example {
        uint8_t array[32];
        long longVal;
        __extension__ union {
            __extension__ struct { short shortVal; };
            struct { Point point; float e; };
        };
        bool boolValue;
        int (*func)(struct __sub *h);
    } Example;
CPP);

$struct = $ffi->new('Example');
$struct->func = (static fn (object $ptr) => 42);

dump($struct);
```

**Before**

```
FFI\CData {#2}
```

**After**

```
FFI\CData<struct Example> size 64 align 8 {#2
  +array: FFI\CData<uint8_t[32]> size 32 align 1 {symfony#18}
  +int32_t longVal: 0
  +int16_t shortVal: 0
  +point: FFI\CData<struct <anonymous>> size 8 align 4 {symfony#17
    +int32_t x: 0
    +int32_t y: 0
  }
  +float e: 0.0
  +bool boolValue: false
  +func: [cdecl] callable(struct __sub*): int32_t {symfony#20
    returnType: FFI\CType<int32_t> size 4 align 4 {symfony#25}
  }
}
```

P.S. I apologize for the multiple force pushes, errors in tests and codestyle have been fixed.

## Review And TODOs

- Pointers
  - [x] Pointer to scalar tests.
  - [x] Pointer to struct tests.
  - [x] "Special" pointer to `char*` tests (with `\0` and without `\0`).
- Possible Errors
  - [x] Do not dump union fields with pointer references (possible SIGSEGV).

Commits
-------

1c7dc52 [VarDumper] Add `FFI\CData` and `FFI\CType` types
chalasr pushed a commit that referenced this pull request Dec 16, 2022
…(HypeMC)

This PR was merged into the 6.2 branch.

Discussion
----------

[HttpKernel] Fix `CacheAttributeListener` priority

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Currently the `CacheAttributeListener` & the `IsGrantedAttributeListener` have the same priority:

```
Registered Listeners for "kernel.controller_arguments" Event
============================================================

 ------- --------------------------------------------------------------------------------------------------------- ----------
  Order   Callable                                                                                                  Priority
 ------- --------------------------------------------------------------------------------------------------------- ----------
  #1      Symfony\Component\HttpKernel\EventListener\CacheAttributeListener::onKernelControllerArguments()          10
  #2      Symfony\Component\Security\Http\EventListener\IsGrantedAttributeListener::onKernelControllerArguments()   10
  #3      Symfony\Component\HttpKernel\EventListener\ErrorListener::onControllerArguments()                         0
 ------- --------------------------------------------------------------------------------------------------------- ----------
```

Since the `CacheAttributeListener` is alphabetically first, it's first to get triggered. This can cause an unauthenticated user to receive a 304 Not modified instead of a 302 Redirect, resulting in the user seeing some stale content from when they were authenticated instead of getting redirected to the login page.

This PR changes the priority of the `CacheAttributeListener` to be lower than that of the `IsGrantedAttributeListener`.

Commits
-------

90eb89f [HttpKernel] Fix CacheAttributeListener priority
chalasr pushed a commit that referenced this pull request Feb 19, 2023
…azak)

This PR was submitted for the 6.2 branch but it was merged into the 5.4 branch instead.

Discussion
----------

[Serializer] Fix CsvEncoder decode on empty data

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Test that reproduces the error: https://gist.github.com/cazak/954d8bfe53d5b9139667eae8fe53957f
The message i get after running the test:
  1x: explode(): Passing null to parameter #2 ($string) of type string is deprecated
    1x in CsvEncoderTest::testSuccess from App\Tests\Functional\Task

Commits
-------

6c22622 [Serializer] Fix CsvEncoder decode on empty data
chalasr pushed a commit that referenced this pull request May 13, 2023
…rows PHP 8.1 deprecation when no user agent is set (juagarc4)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 deprecation when no user agent is set

| Q             | A
| ------------- | ---
| Branch?       |  5.4
| Bug fix?      | yes/no
| New feature?  no
| Deprecations? no
| Tickets       | Fix symfony#49392
| License       | MIT

- Add casting to the second parameter to pass always the right type.

**PHPstan before:**

 ------ --------------------------------------------------------------------------------------------------------
  Line   FirePHPHandler.php
 ------ --------------------------------------------------------------------------------------------------------
  27     Property Symfony\Bridge\Monolog\Handler\FirePHPHandler::$headers has no type specified.
  37     Method Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse() has no return type specified.
  **44     Parameter #2 $subject of function preg_match expects string, string|null given.**
  68     If condition is always true.
 ------ --------------------------------------------------------------------------------------------------------

**PHPstan after:**

 ------ --------------------------------------------------------------------------------------------------------
  Line   FirePHPHandler.php
 ------ --------------------------------------------------------------------------------------------------------
  27     Property Symfony\Bridge\Monolog\Handler\FirePHPHandler::$headers has no type specified.
  37     Method Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse() has no return type specified.
  68     If condition is always true.
 ------ --------------------------------------------------------------------------------------------------------

Commits
-------

4d84c46 [MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 deprecation when no user agent is set
chalasr pushed a commit that referenced this pull request May 13, 2023
…ult Enum parameter in constructor (kapiwko)

This PR was submitted for the 6.3 branch but it was squashed and merged into the 5.4 branch instead.

Discussion
----------

[VarDumper] Fix error when reflected class has default Enum parameter in constructor

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | no
| License       | MIT
| Doc PR        | no

Have classes:

```
enum GeometryType: string
{
    case Geometry = 'GEOMETRY';
}
```

```
final class Geometry
{
    public function __construct(GeometryType $type = GeometryType::Geometry)
    {
    }
}
```

Try to dump reflection of class Geometry:

```
$reflection = new \ReflectionClass(Geometry::class);
dump($reflection);
```

Have error:
`Symfony\Component\VarDumper\Caster\ConstStub::__construct(): Argument #2 ($value) must be of type string|int|float|null, App\Infrastructure\Geometry\GeometryType given, called in [...]/vendor/symfony/var-dumper/Caster/ReflectionCaster.php on line 296`

Commits
-------

d6a7730 [VarDumper] Fix error when reflected class has default Enum parameter in constructor
chalasr pushed a commit that referenced this pull request Dec 6, 2024
…h()` (simoheinonen)

This PR was merged into the 5.4 branch.

Discussion
----------

[MonologBridge] Fix PHP deprecation with `preg_match()`

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

```
preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated
```

Commits
-------

4d7a6f6 Passing null to parameter #2 ($subject) of type string is deprecated
chalasr pushed a commit that referenced this pull request Dec 6, 2024
* 5.4:
  do not mix named and positional arguments in data provider definitions
  session names must not be empty
  fix Contracts directory name in PHPUnit configuration
  Passing null to parameter #2 ($subject) of type string is deprecated
chalasr pushed a commit that referenced this pull request Dec 6, 2024
* 6.4:
  do not mix named and positional arguments in data provider definitions
  session names must not be empty
  fix Contracts directory name in PHPUnit configuration
  Passing null to parameter #2 ($subject) of type string is deprecated
chalasr pushed a commit that referenced this pull request Dec 6, 2024
* 7.1:
  do not mix named and positional arguments in data provider definitions
  session names must not be empty
  add missing properties
  fix Contracts directory name in PHPUnit configuration
  [Validator][CidrValidator] Fix error message for `OutOfRangeNetmask` validation
  Passing null to parameter #2 ($subject) of type string is deprecated
chalasr pushed a commit that referenced this pull request Dec 6, 2024
… not throw exception (lyrixx)

This PR was merged into the 5.4 branch.

Discussion
----------

[HttpKernel] Ensure `HttpCache::getTraceKey()` does not throw exception

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

We have such logs in our logs. It's in our raw PHP logs. They are not caught by monolog, it's too early

```
[11-Oct-2024 01:23:33 UTC] PHP Fatal error:  Uncaught Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException: Invalid method override "__CONSTRUCT". in /var/www/redirection.io/backend/blue/vendor/symfony/http-foundation/Request.php:1234
Stack trace:
#0 /var/www/redirection.io/backend/blue/vendor/symfony/http-kernel/HttpCache/HttpCache.php(728): Symfony\Component\HttpFoundation\Request->getMethod()
#1 /var/www/redirection.io/backend/blue/vendor/symfony/http-kernel/HttpCache/HttpCache.php(207): Symfony\Component\HttpKernel\HttpCache\HttpCache->getTraceKey()
#2 /var/www/redirection.io/backend/blue/vendor/symfony/http-kernel/Kernel.php(188): Symfony\Component\HttpKernel\HttpCache\HttpCache->handle()
#3 /var/www/redirection.io/backend/blue/web/app.php(9): Symfony\Component\HttpKernel\Kernel->handle()
symfony#4 {main}
  thrown in /var/www/redirection.io/backend/blue/vendor/symfony/http-foundation/Request.php on line 1234

```

I managed to reproduced locally.
* Before the patch, without the http_cache, symfony returns a 405
* After the patch, without the http_cache, symfony returns a 405
* Before the patch, with the http_cache, symfony returns a 500, without any information (too early)
* After the patch, with the http_cache, symfony returns a 405

Commits
-------

a2ebbe0 [HttpKernel] Ensure HttpCache::getTraceKey() does not throw exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants