Skip to content
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

[5.x] Static caching file path fallback #9306

Merged
merged 4 commits into from
May 28, 2024
Merged

Conversation

royduin
Copy link
Contributor

@royduin royduin commented Jan 11, 2024

Statamic\StaticCaching\Invalidate sometimes throws errors like:

ErrorException: Trying to access array offset on value of type bool in /vendor/statamic/cms/src/StaticCaching/Cachers/FileCacher.php:163

This is caused by a "malformed url" like //?phpinfo=1 which is saved in the cached urls list. When invalidating the url can't be parsed by parse_url() as this function returns false when it's not a valid url: https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues

@jasonvarga
Copy link
Member

When invalidating

How are you invalidating //?phpinfo=1?

@royduin
Copy link
Contributor Author

royduin commented Jan 11, 2024

That happens automatically when something changes according the invalidation rules in config/statamic/static_caching.php with:

'urls' => [
    '/*'
]

@jasonvarga
Copy link
Member

I can't reproduce an error. Could you provide a sample repo with this problem happening?

@royduin
Copy link
Contributor Author

royduin commented Jan 12, 2024

I'll provide more info shortly. Need to find some time :)

@duncanmcclean
Copy link
Member

I'm marking this PR as a draft in the meantime. When you're able to provide replication steps, feel free to mark it "ready for review" again and we can take another look.

@duncanmcclean duncanmcclean marked this pull request as draft January 18, 2024 10:39
@royduin
Copy link
Contributor Author

royduin commented Feb 22, 2024

Alright, there we go; steps to reproduce this:

  • statamic new statamictest
  • STATAMIC_STATIC_CACHING_STRATEGY=full in the .env
  • In config/statamic/static_caching.php:
    'invalidation' => [

        'class' => null,

        'rules' => [
            'collections' => [
                'pages' => [
                    'urls' => [
                        '/*'
                    ]
                ],
            ]
        ],

    ],
image

@royduin royduin marked this pull request as ready for review February 22, 2024 08:09
@duncanmcclean duncanmcclean changed the base branch from 4.x to 5.x May 14, 2024 14:08
@duncanmcclean duncanmcclean changed the title [4.x] Static caching file path fallback [5.x] Static caching file path fallback May 14, 2024
Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

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

Turns out this was because the domain wasn't being passed along.

If you pass //?phpinfo=1, then parse_url($url) would fail like you mentioned.

But if its http://domain.com//?phpinfo=1, parse_url() works as we expected.

@jasonvarga jasonvarga merged commit 4741f99 into statamic:5.x May 28, 2024
16 checks passed
@royduin royduin deleted the patch-1 branch May 29, 2024 06:22
@royduin
Copy link
Contributor Author

royduin commented May 29, 2024

Thanks! 🚀

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.

3 participants