Skip to content

Commit 9b2c2a4

Browse files
bug symfony#52502 [Config] Prefixing FileExistenceResource::__toString() to avoid conflict with FileResource (weaverryan)
This PR was submitted for the 6.3 branch but it was merged into the 5.4 branch instead. Discussion ---------- [Config] Prefixing `FileExistenceResource::__toString()` to avoid conflict with `FileResource` | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fixes issue in AssetMapper 6.4 | License | MIT Hi! This bug causes a pretty critical AssetMapper 6.4 bug. The problem is that both `FileResource` and `FileExistenceResource` return the same `__toString()` for the same file: * [FileResource::__toString()](https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Config/Resource/FileResource.php#L43-L46) * [FileExistenceResource::__toString()](https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Config/Resource/FileExistenceResource.php#L39-L41) [SelfCheckingResourceChecker](https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Config/Resource/SelfCheckingResourceChecker.php#L40-L45) uses a static cache where the `ResourceInterface::__toString()` is the key for that string. That creates the following bug situation: A) Something checks for `FileExistenceResource` for `foo/bar.php`. This returns true and `SelfCheckingResourceChecker` now has `true` for fresh in its static cache B) Something else checks for `FileResource` for `foo/bar.php`: they are checking to see if the file has been *modified*. But in instead of calling the actual `FileResource::isFresh()` method, it uses the `true` value from the static cache. Cheers! Commits ------- 9e8db58 [Config] Prefixing FileExistenceResource::__toString() to avoid conflict with FileResource
2 parents 0ff9ed4 + 9e8db58 commit 9b2c2a4

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Symfony/Component/Config/Resource/FileExistenceResource.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(string $resource)
3838

3939
public function __toString(): string
4040
{
41-
return $this->resource;
41+
return 'existence.'.$this->resource;
4242
}
4343

4444
public function getResource(): string

src/Symfony/Component/Config/Tests/Resource/FileExistenceResourceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function tearDown(): void
3636

3737
public function testToString()
3838
{
39-
$this->assertSame($this->file, (string) $this->resource);
39+
$this->assertSame('existence.'.$this->file, (string) $this->resource);
4040
}
4141

4242
public function testGetResource()

0 commit comments

Comments
 (0)