cms icon indicating copy to clipboard operation
cms copied to clipboard

[5.x] Static caching file path fallback

Open royduin opened this issue 1 year ago • 6 comments

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

royduin avatar Jan 11 '24 12:01 royduin

When invalidating

How are you invalidating //?phpinfo=1?

jasonvarga avatar Jan 11 '24 15:01 jasonvarga

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

'urls' => [
    '/*'
]

royduin avatar Jan 11 '24 15:01 royduin

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

jasonvarga avatar Jan 11 '24 16:01 jasonvarga

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

royduin avatar Jan 12 '24 07:01 royduin

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 avatar Jan 18 '24 10:01 duncanmcclean

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' => [
                        '/*'
                    ]
                ],
            ]
        ],

    ],
  • Go to http://statamictest.test//?phpinfo=1, yeah this is not something I would go to but bots try crazy things
  • Change the page: http://statamictest.test/cp/collections/pages/entries/home and you'll get the error after the save: image

royduin avatar Feb 22 '24 08:02 royduin

Thanks! 🚀

royduin avatar May 29 '24 06:05 royduin