cms icon indicating copy to clipboard operation
cms copied to clipboard

Failed to open stream: File name too long

Open bomshteyn opened this issue 3 years ago • 5 comments

Bug Description

When saving a post if the slug is over 235 characters there is a server error, because the slug is used as the file name.

I have no added a validation to the slug to not allow it to be over 235 chars. But it would be much more user friendly to either automatically chop off anything over 235 chars by limiting the field length or to only use the first 235 cars when creating the md file.

In current state without me adding validation it was just giving the user a server error.

How to Reproduce

Use blueprint with slug and attempt to store entity with a title of 250 characters.

Environment

Statamic version: 3.2.13

PHP version: 7.4.24

Install method (choose one):

  • Starter kit

bomshteyn avatar Oct 08 '21 17:10 bomshteyn

Actually, I ran into this the other day while reproducing this in another issue.

duncanmcclean avatar Oct 08 '21 18:10 duncanmcclean

Which operating system are you using?

Most operating systems have a limit to the number of characters that can be used as filenames. If your slug + .md goes over that limit, that's where you'll start to see this issue. (eg macos: https://apple.stackexchange.com/a/86617)

My recommendation would be to use shorter slugs. If you really need the long versions of the slugs to show in URLs, you can create another slug field, called something else like long_slug and you can then use that in your collection's routing structure instead of slug.

duncanmcclean avatar Oct 30 '21 11:10 duncanmcclean

Hey, have experienced this both in local (Mac) environment and on the Production Ubuntu Server.

The slug is being auto generated from the title.

I have added a validation to the slug to not allow it to be over 235 chars.

But as mentioned above it would be much more user friendly to either automatically chop off anything over 235 chars by limiting the field length or to only use the first 235 cars when creating the md file.

bomshteyn avatar Nov 01 '21 18:11 bomshteyn

I just saw this issue in a production site.

AFAIK pretty much all OS have a limitation to 255 bytes, it would be sensible to limit the length of the slug by default below that (file extension and other data that might be added automatically)

rrelmy avatar Aug 31 '22 15:08 rrelmy

A workaround could be to add a max:200 validation rule to your slug fields.

jasonvarga avatar Aug 31 '22 15:08 jasonvarga