flarum / issue-archive

0 stars 0 forks source link

Increase Post-content validation max-value #13

Open wolfgang-demeter opened 2 years ago

wolfgang-demeter commented 2 years ago

Regarding the short discussion in https://discuss.flarum.org/d/29812-add-new-validator-to-core/6 i'd like to propose the increase of the max-value for the Posts content validator src/Post/PostValidator.php.

The MySQL-database field type for posts.content was changed from text to mediumtext, which can contain up to 16777215 bytes of data, instead of the 65535 bytes for text.

As @clarkwinkelmann pointed out, the parsed XML of the TextFormatter XML format can be much bigger, then the content entered in the input field. That should be taken into account when increasing the value. But btw. that wasn't considered previously, when text matched the validator with 65535 bytes!

Germany wouldn't be Germany, without definig a Norm-page wich contains approx. 1800 characters (including spaces). Which means you could roughly post about 36 pages worth of text (without formatting) with the current constraint of 65535 charachters. While this is fine for the majority of posts, there are certain use-cases one could think of, which require more text. Like for example detailed analysis, essays or reviews or some scientific work or some extensively formatted content.

I don't have an exact max-value in mind, but if you take a quarter of 16777215 you come up with 4194304, which imho leaves enough room for anything TextFormatter could add.

This should not have any impact on the MySQL search performance. On the contrary. Wildcard-searching in one post should be more efficent then searching over multiple posts in the database - considering the same content (length) being searched.

If not increasing it in general, another option could be to have a select box with pre-defined values or a input-number field in the base settings of Flarum to determine the max value for each installation.

clarkwinkelmann commented 2 years ago

Addendum: the validation rule is actually on the TextFormatter XML because both PostReplyHandler and EditPostHandler feed the validator with $post->getAttributes(), which skips the getContentAttribute() accessor.

So we could put the actual database max column size in there.

But maybe we should also have a validation rule for the non-XML max post size? It could be confusing if we throw a validation error to the user with the length of the XML, and when they compare it with their text length in the editor it doesn't match.

Maybe the "fallback" database validation should have a custom error message like "The internal representation of the post is too big for the database. Try shortening the post", but ideally it would never show up if we set a shorter validation for the actual input.